Search code examples
javaspring-bootjpadependency-injectionspring-repositories

Springboot repository could not be found


I have issue with this error. - Springboot cannost inject 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.

On my computer working everything OK but If I want deploy app on Windows server as windows service with WinSW.NET4.exe application crash with this error.

I have two data source (two different SQL databases on same server) first database working OK.

I already tryed @EntityScan @ComponentScan withou success. I tryed remove repository but every repository from this database throw this error.

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

[Project structure]1

I am running Java 11, Springboot 2.4.2. and MSSQL


Solution

  • You also need @EnableJpaRepositories

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

    2 more things that I have noticed.

    1)

    "cz.fry.bmw.om.DAO"
    

    in your project structure it seems like

    "cz.fry.bmw.OM.DAO"
    

    2)

    @ComponentScan
    

    provide the root package here

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