title: what's the equivalent code based configuration to add log4j in spring MVC 3.0+
body: <p>I am migrating my Spring MVC project to code based configuration, but not sure how to add a listener, </p>
  
  <p>here's what in my web.xml </p>
  
  <pre><code>&lt;context-param&gt;
      &lt;param-name&gt;log4jConfigLocation&lt;/param-name&gt;
      &lt;param-value&gt;WEB-INF/spring/log4j.xml&lt;/param-value&gt;
  &lt;/context-param&gt;
  
  &lt;listener&gt;
      &lt;listener-class&gt;org.springframework.web.util.Log4jConfigListener&lt;/listener-class&gt;
  &lt;/listener&gt;
  </code></pre>
  
  <p>Here's my init class:</p>
  
  <pre><code>@Order(1)
  public class Initializer extends
          AbstractAnnotationConfigDispatcherServletInitializer {
  
      @Override
      protected Class&lt;?&gt;[] getRootConfigClasses() {
          return new Class[] { RootConfig.class, SecurityConfig.class };
      }
  
      @Override
      protected Class&lt;?&gt;[] getServletConfigClasses() {
          return new Class[] { WebConfig.class };
      }
  
      @Override
      protected String[] getServletMappings() {
          return new String[] { "/" };
      }
  
  }
  </code></pre>
  
  <p>I checked declaration of <code>AbstractAnnotationConfigDispatcherServletInitializer</code>, 
  and tried to implement <code>onStartUp()</code> like below, but it complains <code>addListener</code> is not found.</p>
  
  <pre><code>@Override
      public void onStartup(ServletContext container) throws ServletException {
          org.springframework.web.util.Log4jConfigListener log4jConfigListener = new org.springframework.web.util.Log4jConfigListener();
          container.addListener(log4jConfigListener);
          super.onStartup(container);
      }
  </code></pre>