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无法注入

 

转载于:https://www.cnblogs.com/dashuaiguo/p/10506956.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值