2

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") ?

Dimitri Kopriwa
  • 13,139
  • 27
  • 98
  • 204

1 Answers1

5

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.

Faraz
  • 6,025
  • 5
  • 31
  • 88
  • Thanks for your answer, I am already having login level for `org` to `TRACE`, however, the repository still does not get scan, how can I understand why ? – Dimitri Kopriwa Apr 17 '20 at 11:27
  • Can you move `@ComponentScan` out of `KopaxgroupApiConfig` to main class? And use this to scan different packages: `@ComponentScan({"com.my.package.first","com.my.package.second"})`. – Faraz Apr 17 '20 at 19:24
  • Yes I already tried to do that, unfortunatly, the `@ComponentScan` seems to just ignore the class path for some reason... That is what I need to find out – Dimitri Kopriwa Apr 17 '20 at 20:01
  • I m sorry I have no idea now. – Faraz Apr 17 '20 at 23:16
  • What happened? How did you solve this? @DimitriKopriwa – Faraz Apr 18 '20 at 16:13
  • Actually, I did not solved it by keeping the current classpath, I had to move up everything which was into `callMeBack` and then it started to work, though I think your answer would still help other in such case to debug and should be rewarded for the time and effort. thanks – Dimitri Kopriwa Apr 18 '20 at 17:28