javaspringspring-bootclasspathcomponent-scan

How to see the list of classpath scanned by @ComponentScan to resolve NoSuchBeanDefinitionException


In a Spring boot 1.5.9 application, I have @SpringBootApplication on my main class.

I also have @KopaxgroupApi annotation, with :

@Retention(RUNTIME)
@Target(TYPE)
@Import(KopaxgroupApiConfig.class)
public @interface KopaxgroupApi {

    @AliasFor(annotation = Import.class, attribute = "value")
    Class<?>[] value() default { KopaxgroupApiConfig.class };
}

With KopaxgroupApiConfig.class being:

@Configuration
@ComponentScan(basePackages = { KopaxgroupApiConfig.CLASSPATH })
public class KopaxgroupApiConfig {
    public static final String CLASSPATH = "com.kopaxgroup.api";
}

I have created a new project within com.kopaxgroup.api.customerManagement.callMeBack and there I have repository and service stored in respectively in directories repository and service.

The CallMeBackServiceImpl cannot find the CallMeBackRepository.

I am having the following error on startup:

Application failed to start due to an exception
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.kopaxgroup.api.customerManagement.callMeBack.repository.CallMeBackRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1493)

Parameter 0 of constructor in com.kopaxgroup.api.customerManagement.callMeBack.service.impl.CallMeBackServiceImpl required a bean of type 'com.kopaxgroup.api.customerManagement.callMeBack.repository.CallMeBackRepository' that could not be found.


Action:

Consider defining a bean of type 'com.kopaxgroup.api.customerManagement.callMeBack.repository.CallMeBackRepository' in your configuration.

I have tried to move CallMeBackRepository into com.kopaxgroup.api.customerManagement.callMeBack.service.impl but the error staid.

I have some similar package and they all can boot, I don't see any difference on the configuration.

This happen when creating a new jar.

I have added a bunch of @ComponentScan but I couldn't solve it, how can I dig further and see the list of classpath used during @ComponentScan("com.kopaxgroup.api") ?


Solution

  • You are able to see all the beans that were created or rejected in Springboot along with the reasons for their creation and rejection.

    List of beans in application context is provided by ConditionEvaluationReportLoggingListener

    To print those beans: put this in application.properties logging.level.org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportLoggingListener=debug

    I am unable to find which package ConfigurationReportLoggingInitializer sits in because that's the class that's responsible for printing beans in Springboot version 1.5.9. The work around is to provide following properties: logging.level.root=debug. And then CTRL + F ConfigurationReportLoggingInitializer.