SpringBoot集成spring-data-jpa注入Bean失敗


當項目結構正常(spring管理的Bean在SrpingBoot啟動類平級或下級,支持spring掃描時),實現類上加 @Service注解,在實現類中注入dao層的Bean時,項目無法啟動,無法找到注入dao層的Bean,會報如下錯:

Description:
Field businessInfoBelongRepository in com.example.test.service.impl.QueryHouseListImpl required a bean of type 'com.example.test.repository.BusinessInfoBelongRepository' that could not be found.

 Action:

 Consider defining a bean of type 'com.example.test.repository.BusinessInfoBelongRepository' in your configuration.

 

解決辦法:pom文件中需要引入spring-data-jpa的的Maven包

 <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-data-jpa</artifactId>
 </dependency>

 

總結:SpringDataJPA內部使用了類代理的方式讓繼承了(JpaRepository)它接口的子接口都以spring管理的Bean的形式存在,當你沒有引用spring-data-jpa的時,則在實現類中注入dao層Bean會提示dao層的bean無法注入

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM