仅实现 JpaSpecificationExecutor 的存储库会在启动 Spring boot 应用程序时导致错误

发布于 2025-01-16 13:48:13 字数 1748 浏览 1 评论 0原文

我们在启动 Spring Boot 应用程序时遇到了问题。我们添加了一个新的 API,其中包含一个控制器、一个服务类和两个表的两个存储库类。这是主表存储库

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Repository;    
import com.sixdee.wallet.core.domain.PromoTicketMaster;

@Repository
public interface PromoTicketMasterRepo extends JpaSpecificationExecutor<PromoTicketMaster> {

}

我们查看了这个答案 Spring Data JPA 中的 CrudRepository 和 JpaRepository 接口有什么区别?在创建此存储库之前,因为它也用于分页方法。上面说,由于上面提到的继承,JpaRepository将拥有CrudRepository和PagingAndSortingRepository的所有功能。但应用程序并未使用此 Repo 配置启动,并且控制台显示此错误。自动装配很好。

*************************** APPLICATION FAILED TO START
***************************

Description:

Field promoTicketMasterRepo in com.sixdee.wallet.core.service.impl.PromoTicketServiceImpl required a bean of type 'com.sixdee.wallet.core.repository.PromoTicketMasterRepo' that could not be found.

The injection point has the following annotations:
    - @org.springframework.beans.factory.annotation.Autowired(required=true)


Action:

Consider defining a bean of type 'com.sixdee.wallet.core.repository.PromoTicketMasterRepo' in your configuration.

然后我们像这样更改了Repo并启动了应用程序。

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import com.sixdee.wallet.core.domain.PromoTicketMaster;

@Repository
public interface PromoTicketMasterRepo extends JpaSpecificationExecutor<PromoTicketMaster>, CrudRepository<PromoTicketMaster, String> {

}

第一种方法有什么问题

we were facing issues while starting our Spring Boot Application. We added a new API with a Controller, a Service class, and two Repository classes for two tables. This is the master table repository

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Repository;    
import com.sixdee.wallet.core.domain.PromoTicketMaster;

@Repository
public interface PromoTicketMasterRepo extends JpaSpecificationExecutor<PromoTicketMaster> {

}

We had a look at this answer What is difference between CrudRepository and JpaRepository interfaces in Spring Data JPA? before creating this Repo as it was used for Pagination methods as well. It said that Because of the inheritance mentioned above, JpaRepository will have all the functions of CrudRepository and PagingAndSortingRepository . But the application didn't start with this Repo configuration and the console showed this error. The autowiring was fine.

*************************** APPLICATION FAILED TO START
***************************

Description:

Field promoTicketMasterRepo in com.sixdee.wallet.core.service.impl.PromoTicketServiceImpl required a bean of type 'com.sixdee.wallet.core.repository.PromoTicketMasterRepo' that could not be found.

The injection point has the following annotations:
    - @org.springframework.beans.factory.annotation.Autowired(required=true)


Action:

Consider defining a bean of type 'com.sixdee.wallet.core.repository.PromoTicketMasterRepo' in your configuration.

Then we changed the Repo like this and the application was started.

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import com.sixdee.wallet.core.domain.PromoTicketMaster;

@Repository
public interface PromoTicketMasterRepo extends JpaSpecificationExecutor<PromoTicketMaster>, CrudRepository<PromoTicketMaster, String> {

}

What was wrong with the first approach

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文