首页 > 解决方案 > Sprin Boot: Repository bean not found

问题描述

I'm building applications that could use the same entities and repository classes. So I create a lib with these objects and installed it in Maven and included a dependency in pom.xml in the new project. However, when I call the page the error below appears.

The lib contains the configuration DB class and in the all declaration of the service in the new project's controller I use the annotation @Autowired. Tomcat does not show any problem on start.

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-08-02 09:54:53.546 ERROR 20368 --- [  restartedMain] o.s.b.d.LoggingFailureAnalysisReporter   : 

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

Description:

Field repository in br.com.service.PersonService required a bean of type 'br.com.repository.PersonRepository' 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 'br.com.repository.PersonRepository' in your configuration.

EDIT:

Configuration:

@SpringBootApplication
@EntityScan(basePackages = { "br.com.*" })
@EnableCassandraRepositories(basePackages = { "br.com.*" })
@ComponentScan(basePackages = {"br.com.*"})
public class App extends SpringBootServletInitializer 
{
    public static void main( String[] args )
    {
        SpringApplication.run(App.class, args);
    }
}

POM.XML with my lib with the commons objects:

<dependency>
     <groupId>br.com</groupId>
     <artifactId>objetos.base</artifactId>
     <version>1.2.2</version>
</dependency>

Lib Repository:

@Repository
public interface  PersonRepository  extends CassandraRepository<Person, UUID>{

Lib Service:

@Service
public class PersonService {

    @Autowired
    private PersonRepository repository;

Does anyone have any idea what is happening?

标签: springspring-bootspring-data-jpaspring-data

解决方案


推荐阅读