Spring @Import annotation isn't working as expected

Viewed 472

I'm developing a multi-module project using Spring Boot 2.0.5.RELEASE, Java 8. It consists of model, DAO, and various microservices. Usage of DAO beans is provided by the @Import annotation, as listed below:

Microservice:

@SpringBootApplication
@EnableBatchProcessing
@EnableDao
public class Application {

    public static ConfigurableApplicationContext CONTEXT;

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

DAO:

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Import(DaoConfiguration.class)
public @interface EnableDao {
/* empty */
}
@Configuration
@EntityScan("blah.blah.blah.dao")
@EnableJpaRepositories("blah.blah.blah.dao.repo")
public class DaoConfiguration {
/* Some tricks with EntityManager also */
}
@Repository
public interface SomethingRepo extends JpaRepository<Something, Long> {
/* + some default methods */
}

But I've got running the code:

org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'blah.blah.blah.dao.repo.SomethingRepo' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}

Why the hell my code doesn't create the bean? What can be the cause?

1 Answers

Still don't know why it has such behaviour, but I found the solution adding annotation @EnableJpaRepositories(basePackageClasses = {SomethingRepo.class}) to the Application.class

Related