Springboot 使用JPA Repository 注入失败问题

报错如下:

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

Description:

Field customerRepository in com.xx.xx.xx.customer.service.impl.CustomerServiceImpl required a bean of type 'com.xx.xx.xx.customer.repository.CustomerRepository' 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.xx.xx.xx.customer.repository.CustomerRepository' in your configuration.

Disconnected from the target VM, address: '127.0.0.1:61358', transport: 'socket'

Process finished with exit code 1

环境如下:

springboot 2.1.6.RELEASE。

 

springboot 启动类配置如下:

package com.xx.xx.xx.application;

import com.alibaba.nacos.spring.context.annotation.config.NacosPropertySource;
import com.spring4all.swagger.EnableSwagger2Doc;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.scheduling.annotation.EnableAsync;

@SpringBootApplication
@NacosPropertySource(dataId = "xx, autoRefreshed = true)
@EnableDubbo
@EnableAsync
@EnableSwagger2Doc
@EnableJpaAuditing
// TODO 问题原因在这里,需要手动开启 JpaRepositories 的注入
// @EnableJpaRepositories(basePackages = OmsApplication.xxPACKAGES)
@EntityScan({OmsApplication.xxPACKAGES})
@ComponentScan(basePackages = {OmsApplication.xxPACKAGES})
public class OmsApplication {
    static final String xxPACKAGES = "com.xx.*";

    public static void main(String[] args) {
        SpringApplication.run(OmsApplication.class, args);
    }

}

原因:

https://docs.spring.io/spring-data/jpa/docs/2.1.6.RELEASE/reference/html/#repositories 

springboot 官网上是这么说的。至于为什么要这么搞,有待后续学习了

 反思:

这个问题我查了一两个小时,但是查询的方向错误了,基本一直在查找博客。这还是学习方式和解决问题的方式有问题。

大佬出差回来后,咨询了一下大佬,大佬说看官方文档,然后找了一找,很快发现了解决问题的办法。

官方文档极其重要,推荐各位看客,遇到问题时先查找官方文档。我自身也要改变思路。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值