Getting Spring To Read Your Log4j Config

Jun 28th, 20071 Comment

I’m using [The Spring Framework](http://www.springframework.org/) to build a new application. Spring is cool — it can do a lot and there is a lot to learn about it. One cool thing I just figured out it [logging injection](http://www.devx.com/Java/Article/30799). One thing that took me a while to figure out is to get Spring (and my Spring-configured classes) to use my `log4j.xml` file instead of the `log4j.properties` that is hidden somewhere in the Spring jar.

I googled and googled and finally put together a couple of answers and got it to work. So now I’m putting it here so you, gentle reader, don’t have to go through that much work:

class=”org.springframework.beans.factory.config.MethodInvokingFactoryBean”>

value=”org.springframework.util.Log4jConfigurer” /> classpath:log4j.xml

Note that this is pretty much a boiler-plate — just copy it into your context configuration and make sure that your `log4j.xml` file is somewhere on your classpath. Then things will start working wonderfully

One Response to “Getting Spring To Read Your Log4j Config”

  1. ignatalexeyenko says:

    Thank you, this is awesome.

Leave a Reply

You must be logged in to post a comment.