找不到 Spring Boot 存储库

Springboot repository could not be found

我对这个错误有疑问。 - 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

我是运行Java11、Springboot 2.4.2。和 MSSQL

你还需要@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");