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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 16:41:15  来源:igfitidea点击:

Logging Spring bean creation / dependency injection

javaspringdependency-injectionlog4j

提问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.DefaultListableBeanFactorylogger 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