如何在tomcat应用程序中记录spring组件扫描

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

我被迫对在 tomcat 中运行的 springboot 应用程序进行一些调试,并怀疑组件扫描没有选择至少一个组件的正确实现。

如何在不更改任何代码的情况下让tomcat记录springboot组件扫描过程?

我尝试将以下内容添加到conf/logging.properties,但它没有任何作用:

logging.level.org.springframework.core.io.support=DEBUG
logging.level.org.springframework.context.annotation=DEBUG

我不是企业 Java 开发人员,见鬼,我什至不是真正的 Java 开发人员...

spring-boot tomcat9
1个回答
0
投票

Spring 组件扫描很复杂并且发生在不同的级别。如果不确定需要什么类型的信息或详细程度,一个好的选择是在更高级别的包中启用跟踪。输出将包括与每个日志行对应的包,这将有助于将结果范围缩小到预期的范围。示例:

logging.level.org.springframework=TRACE

通过上述设置,可以看到一些有趣的日志,可能比必要的更多。根据详细程度和所需信息的类型,现在可以通过在特定日志级别指定更深级别的包来缩小日志范围:

Spring bean工厂支持:

logging.level.org.springframework.beans.factory.support=TRACE

显示如下日志:

o.s.b.f.s.DefaultListableBeanFactory: Finished creating instance of bean 'org.springframework.boot.autoconfigure.sql.init.SqlInitializationAutoConfiguration'
o.s.b.f.s.DefaultListableBeanFactory: Returning cached instance of singleton bean 'org.springframework.boot.context.properties.BoundConfigurationProperties'

Spring bean自动配置:

logging.level.org.springframework.boot.autoconfigure=DEBUG

显示如下日志:

WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter#beanNameViewResolver:
  Did not match:
     - @ConditionalOnMissingBean (types: org.springframework.web.servlet.view.BeanNameViewResolver; SearchStrategy: all) found beans of type 'org.springframework.web.servlet.view.BeanNameViewResolver' beanNameViewResolver (OnBeanCondition)
© www.soinside.com 2019 - 2024. All rights reserved.