How do you log spring component scanning in a tomcat application

23 Views Asked by At

I have been dumped into doing some debugging of a springboot application running in tomcat and have a suspicion that the component scan is not choosing the correct implementation of at least one component.

How can I get tomcat to log the springboot component scan process without changing any code?

I have tried adding the following to the conf/logging.properties, but it does nothing:

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

I am not an enterprise java developer, hell, I am not really even a java developer...

1

There are 1 best solutions below

0
rph On

Spring component scanning is complex and happens at different levels. If unsure of what type of information or verbosity required, one good option is to enable trace at a higher-level package. The output will include the package corresponding to each log line, which will help narrow down the results to what's intended. Example:

logging.level.org.springframework=TRACE

With the above set, it's possible to see some interesting logs, probably more than necessary. Depending on the level of verbosity and the type of information required, one can now narrow down the logs by specifying a deeper-level package at a specific log level:

Spring bean factory support:

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

Which shows logs like:

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 auto-configuration:

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

Which shows logs like:

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)