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