如何查看由@ComponentScan扫描以解决NoSuchBeanDefinitionException的类路径列表

问题描述 投票:0回答:1

在Spring boot 1.5.9应用程序中,主类上有@SpringBootApplication

我也有@KopaxgroupApi批注,带有:

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

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

KopaxgroupApiConfig.class为:

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

我已经在com.kopaxgroup.api.customerManagement.callMeBack中创建了一个新项目,并且我的存储库和服务分别存储在目录repositoryservice中。

CallMeBackServiceImpl找不到CallMeBackRepository

启动时出现以下错误:

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.

我曾尝试将CallMeBackRepository移至com.kopaxgroup.api.customerManagement.callMeBack.service.impl,但错误仍然存​​在。

我有一些类似的程序包,它们都可以启动,我认为配置没有任何区别。

这在创建新的jar时发生。

我添加了一堆@ComponentScan,但无法解决,如何进一步挖掘并查看在@ComponentScan("com.kopaxgroup.api")期间使用的类路径列表?

java spring spring-boot classpath component-scan
1个回答
0
投票

使用Springboot时,您可以查看所有已创建的bean或拒绝创建bean(由于某些条件不匹配)。

这些在应用程序上下文中的bean列表由ConditionEvaluationReportLoggingListener提供

要打印那些bean:将其放入application.properties logging.level.org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportLoggingListener=debug

我无法找到ConfigurationReportLoggingInitializer所在的软件包,因为那是负责在Springboot 1.5.9版中打印bean的类。解决方法是提供以下属性:logging.level.root=debug。然后按CTRL + F ConfigurationReportLoggingInitializer

© www.soinside.com 2019 - 2024. All rights reserved.