I am using Hibernate 4.3.7.Final and Log4j2 in my Spring MVC webapp, published via Tomcat 7. All configuration is done via JavaConfig (i.e. there is no web.xml or other XML config files).
By default the Hibernate logging does not go through Log4j, for reasons explained in the Apache wiki. In order to resolve this I need to create a system setting as follows:
System.setProperty("org.jboss.logging.provider", "slf4j");
As my application is a webapp there is no Main thread, and as a result I an unsure where to put this System.setProperty
call. Any advice would be appreciated.
You could define this system property in context listener which is the first entry point as below:
You could even define system property using spring as below:
And then you could say something like:
So this means system property will be setted first and then hibernate bean is going to be initialised.
If you are using some
WebApplicationInitializer
implementation to bootstrap your Spring application (which I assume you are since you have no web.xml) you could put it inonStartup()
method like this: