Logging Spring bean creation / dependency injection

眉间皱痕 提交于 2019-12-22 04:29:51

问题


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:

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).


回答1:


Looks like org.springframework.beans.factory.support.DefaultListableBeanFactory logger is the best you can get.

Also simply try turning on ALL logging level for the whole org.springframework - maybe you'll find something more useful.




回答2:


You can use a Log4jConfigListener in your web.xml:

http://cristianvrabie.blogspot.com/2008/09/spring-commonslogging-and-log4j.html



来源:https://stackoverflow.com/questions/6624610/logging-spring-bean-creation-dependency-injection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!