如何打开Spring的组件扫描调试信息?

时间:2014-03-24 00:45:42

标签: debugging spring-mvc logging

我试图找出我正在维护的应用程序使用的数据库表的数量。我在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" />

还有其他与此项目相关联的子项目,其中@Entity@Repository被广泛使用。我想如果我能够以某种方式打开Spring的调试,它会列出所有的类名,当它根据基础包扫描它们时,我应该能够找到所有的jpa存储库。如何打开弹簧调试以吐出这些信息?

这就是我在log4j.properties中的内容:

log4j.rootLogger=error, file
log4j.category.org.hibernate=debug, hb
log4j.category.org.springframework=debug, spring

3 个答案:

答案 0 :(得分:15)

这是一个有点老话题,但我找到了对我有用的解决方案(Spring 4.1.7):

<logger name="org.springframework.core.io.support" level="debug"/> <logger name="org.springframework.context.annotation" level="debug"/>

答案 1 :(得分:2)

处理注册存储库的类是org.springframework.data.repository.config.RepositoryConfigurationDelegate。您需要将rootLogger级别设置为调试或配置log4j以使org.springframework.data.repository.config.RepositoryConfigurationDelegate或其任何父级具有日志级别DEBUG的子记录器。

答案 2 :(得分:0)

打开调试级别日志记录:

  1. org.springframework.context.annotation 用于组件扫描报告:

示例:

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 用于自动配置报告。

示例:

ErrorMvcAutoConfiguration matched:
      - @ConditionalOnClass found required classes 'javax.servlet.Servlet', 'org.springframework.web.servlet.DispatcherServlet' (OnClassCondition)
      - found 'session' scope (OnWebApplicationCondition)