How to turn on Spring's component-scan debugging info?
Asked Answered
C

4

20

I am trying to find out the number of database tables the application I am maintaining, uses. I have this in my appContext.xml

 <context:component-scan base-package="com.foo, com.bar" use-default-filters="false">
 <context:include-filter type="annotation" expression="org.springframework.stereotype.Service" />
 <context:include-filter type="annotation" expression="org.springframework.stereotype.Component" />
 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
 </context:component-scan>
         ....
 <jpa:repositories base-package="com.foo.abc, com.bar.def" />

There are other sub projects associated with this project where @Entity and @Repository have liberally been used. I am thinking if I am just able to turn on Spring's debugging somehow, which will list all classnames as and when it scans them based on the base package, I should be able to find all jpa repositories. How can I turn on springs debugging to spit out this information ?

This is what I have in my log4j.properties :

log4j.rootLogger=error, file
log4j.category.org.hibernate=debug, hb
log4j.category.org.springframework=debug, spring
Caulfield answered 24/3, 2014 at 0:45 Comment(0)
R
25

It's a bit old topic but I found solution that worked for me (Spring 4.1.7):

<logger name="org.springframework.core.io.support" level="debug"/>
<logger name="org.springframework.context.annotation" level="debug"/>
Ranchero answered 19/1, 2016 at 9:31 Comment(2)
By default (web-starter) Spring uses Logback so this should be put in a logback.xml file.Wares
malformed xml, where should this go?Artima
M
5

You can also set the properties mentioned above in the application.properties (or e.g. application-development.properties)

logging.level.org.springframework.core.io.support=DEBUG
logging.level.org.springframework.context.annotation=DEBUG
Mayst answered 31/3, 2022 at 9:28 Comment(0)
S
4

The class that handles registering the repositories is org.springframework.data.repository.config.RepositoryConfigurationDelegate. You need to either set your rootLogger level to debug or configure log4j to have a child logger for org.springframework.data.repository.config.RepositoryConfigurationDelegate or any of its parents with log level DEBUG.

Soudan answered 24/3, 2014 at 2:1 Comment(0)
M
0

Turn on debug level logging for:

  1. org.springframework.context.annotation for component scan report:

Example:

2021-05-01 02:58:51.553 [Test worker] [DEBUG] o.s.c.a.ClassPathBeanDefinitionScanner - Identified candidate component class: file [/absolute/path/to/TestController.class]
  1. org.springframework.boot.autoconfigure.logging for auto configuration report.

Example:

ErrorMvcAutoConfiguration matched:
      - @ConditionalOnClass found required classes 'javax.servlet.Servlet', 'org.springframework.web.servlet.DispatcherServlet' (OnClassCondition)
      - found 'session' scope (OnWebApplicationCondition)
Merge answered 1/5, 2021 at 3:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.