java 记录 Spring bean 创建/依赖注入
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6624610/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Logging Spring bean creation / dependency injection
提问by Ondrej Skalicka
I'm looking for a way to set up Log4j
(or any other logger) so that I can see in log whenever Spring creates a bean or sets a bean property. Eg. something like this:
我正在寻找一种设置Log4j
(或任何其他记录器)的方法,以便每当 Spring 创建 bean 或设置 bean 属性时,我都可以在日志中看到。例如。像这样:
1:00:00 Creating bean Foo (Foo@ef5c94)
1:00:01 Creating bean Bar (Bar@147a87e)
1:00:02 Setting bean Foo (Foo@ef5c94) to Bar (Bar@147a87e)
(...)
Is this easily possible? I'm using Spring 2.5.6
(no choice there :/ ) and Log4j
(version doesn't matter I expect).
这很容易吗?我正在使用Spring 2.5.6
(那里别无选择:/)和Log4j
(版本与我期望的无关)。
采纳答案by Tomasz Nurkiewicz
Looks like org.springframework.beans.factory.support.DefaultListableBeanFactory
logger is the best you can get.
看起来org.springframework.beans.factory.support.DefaultListableBeanFactory
记录器是你能得到的最好的。
Also simply try turning on ALLlogging level for the whole org.springframework
- maybe you'll find something more useful.
也只需尝试为整体打开所有日志记录级别org.springframework
- 也许您会发现更有用的东西。
回答by Mark Pope
You can use a Log4jConfigListener in your web.xml:
您可以在 web.xml 中使用 Log4jConfigListener:
http://cristianvrabie.blogspot.com/2008/09/spring-commonslogging-and-log4j.html
http://cristianvrabie.blogspot.com/2008/09/spring-commonslogging-and-log4j.html