【问题标题】:Springboot repository could not be found找不到 Spring Boot 存储库
【发布时间】:2021-02-19 11:13:38
【问题描述】:

我有这个错误的问题。 - Springboot 不能注入 JPARepository。

    Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-02-19 10:07:59.712 ERROR 6912 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

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

Description:

Field enginePartRepository in cz.fry.bmw.OM.services.OrderService required a bean of type 'cz.fry.bmw.OM.DAO.coreid.EnginePartRepository' 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 'cz.fry.bmw.OM.DAO.coreid.EnginePartRepository' in your configuration.

在我的计算机上一切正常,但是如果我想在 Windows 服务器上部署应用程序作为 Windows 服务,WinSW.NET4.exe 应用程序崩溃并出现此错误。

我有两个数据源(同一服务器上有两个不同的 SQL 数据库)第一个数据库工作正常。

我已经尝试过@EntityScan @ComponentScan 没有成功。 我尝试删除存储库,但该数据库中的每个存储库都会抛出此错误。

@ComponentScan
@EntityScan("cz.fry.bmw.om.DAO")
@EnableAutoConfiguration
@SpringBootApplication
public class OrderManagementApplication {

[Project structure]1

我正在运行 Java 11、Springboot 2.4.2。和 MSSQL

【问题讨论】:

    标签: java spring-boot jpa dependency-injection spring-repositories


    【解决方案1】:

    你还需要@EnableJpaRepositories

    @EnableJpaRepositories(basePackages = {"cz.fry.bmw.om.DAO"}) <---------
    @ComponentScan
    @EntityScan("cz.fry.bmw.om.DAO")
    @EnableAutoConfiguration
    @SpringBootApplication
    public class OrderManagementApplication {
    

    我注意到的另外 2 件事。

    1)

    "cz.fry.bmw.om.DAO"
    

    在您的项目结构中看起来像

    "cz.fry.bmw.OM.DAO"
    

    2)

    @ComponentScan
    

    在这里提供根包

    @ComponentScan("cz.fry.bmw.OM");
    

    【讨论】:

    • 如果我添加了它在我的机器上也停止工作:-|
    • 出现什么错误?你肯定需要我在这里写的注释
    • 谢谢!错误的配置和 om -> OM 是问题。非常感谢!
    猜你喜欢
    • 2021-06-09
    • 1970-01-01
    • 2020-10-24
    • 2021-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-06
    相关资源
    最近更新 更多