【发布时间】:2021-01-03 06:46:43
【问题描述】:
我有一个 spring boot 应用程序,它使用标记接口来定义应该用于组件扫描的包:
@ComponentScan(basePackageClasses = {ModelComponents.class, WebComponents.class, ServiceComponents.class})
在ModelComponents 下的一个包中,定义了一个用作服务的接口,并在ServiceComponents 中实现了它,但不知何故没有被拾取。
在 spring 包上使用调试级别调试(VM 选项:-Dlogging.level.org.springframework=DEBUG)我可以看到前两个组件中的所有 spring bean 都被拾取,但第三个组件中没有。
与How to turn on Spring's component-scan debugging info? 中描述的限制到更具体的包相比,启用此调试信息可提供更多输出,但我从中得到的只是日志输出,例如:
DEBUG | .c.a.ClassPathBeanDefinitionScanner | | Identified candidate component class: file [...\ActivityLogService.class]
DEBUG | .c.a.ClassPathBeanDefinitionScanner | | Identified candidate component class: file [...TopayMwApplicationProperties.class]
DEBUG | .c.a.ClassPathBeanDefinitionScanner | | Identified candidate component class: file [...ChallengeService.class]
这告诉了我所有关于找到的 bean 的信息,但它没有给出任何关于其他的提示:因为包被忽略而没有找到它们,或者 spring 查看了基本包并没有找到 bean?
有没有办法获取组件扫描考虑使用哪个包或使用哪个标记接口的信息?
如何在日志中识别?
【问题讨论】:
-
@M.Deinum 已关闭并已被删除,因为它缺少一些细节表明它不是 stackoverflow.com/questions/22599238/… 的副本
标签: java spring spring-boot