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.

我试图搬进CallMeBackRepositorycom.kopaxgroup.api.customerManagement.callMeBack.service.impl,但错误仍然存​​在。

我有一些类似的软件包,它们都可以启动,我看不出配置有什么不同。

创建新 jar 时会发生这种情况。

我已经添加了一堆@ComponentScan但我无法解决它,我怎样才能进一步挖掘并查看期间使用的类路径列表@ComponentScan("com.kopaxgroup.api")

4

1 回答 1

2

您可以看到在 Springboot 中创建或拒绝的所有 bean。您还可以查看创建或拒绝 bean 的原因。

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

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

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

于 2020-04-17T02:46:14.647 回答