Registering Spring bean initialization with Log4J

When I start my application, it stops when the beans are initialized but does not display any log entries. So I don't know what happened:

Log4j.properties

log4j.rootLogger=DEBUG, stdout, R

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
org.springframework=DEBUG
org.springframework.beans.factory.support=DEBUG
log4j.logger.org.springframework.beans.factory.support=DEBUG
log4j.logger.org.springframework.beans=DEBUG
log4j.category.org.springframework.beans.factory=DEBUG

log4j.logger.org.springframework=DEBUG

log4j.logger.org.hibernate.hql.ast.AST=info
log4j.logger.org.hibernate.tool.hbm2ddl=warn
log4j.logger.org.hibernate.cache=info
log4j.logger.org.hibernate.jdbc=debug
log4j.logger.org.hibernate.type=trace 
log4j.additivity.org.hibernate.SQL=false
log4j.logger.org.hibernate.transaction=debug
log4j.logger.java.sql.Statement=DEBUG

log4j.appender.stdout.layout.ConversionPattern=%d %t %C{1}- %m%n
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=${log4j.appender.R.File}
log4j.appender.R.MaxFileSize=2MB
log4j.appender.R.MaxBackupIndex=0
log4j.appender.R.Append=true
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%d %t (%l) - %m%n

      

I want to get something like:

"BeanName" initialized 
"BeanName" initialized
etc...

      

So, I would know where the initialization stopped. Is it possible to get this kind of output in the logs when beans are initialized?

+3


source to share


1 answer


You need to set org.springframework.beans.factory.support.DefaultListableBeanFactory "to the debug level . The result looks something like this:

... - Creating instance of bean ...
... - Finished creating instance of bean  ...

      

Update:



Add this to log4j.properties:

log4j.logger.org.springframework.beans.factory.support.DefaultListableBeanFactory=DEBUG

      

Be aware that Spring uses the commons-logging framework , so these lines won't show up in your Log4J logs. They use SLF4J to redirect . Add slf4j-api.jar, jcl-over-slf4j.jar, slf4j-log4j12.jar and log4j.jar to your lib directory and remove communities -logging.jar from it.

+4


source







All Articles