title: Spring methods being called twice
body: <p>I have a Spring, PrimeFaces JSF application configured to load an application through a class that implements <code>WebApplicationInitializer</code> rather than <code>web.xml</code> (I do still have a bare <code>web.xml</code>) though.  The problem is on application start and basically throughout the whole application, methods are being called twice! Best explanation I found is possible double loading of one of the listeners. I don't see I'm doing that.  Attached is my <code>WebApplicationInitializer</code> class below.  I'm not sure what to else to provide to resolve my issue.  Even managed bean methods are being called twice.  </p>
  
  <pre><code>public class WebAppInitializer implements WebApplicationInitializer {
  
  @Override
  public void onStartup(ServletContext servletContext) throws ServletException {
  
      final CharacterEncodingFilter cf = new CharacterEncodingFilter();
      cf.setEncoding("UTF-8");
      cf.setForceEncoding(true);
  
      servletContext.addListener(new RequestContextListener());
  
      servletContext
              .addFilter(
                      "ShiroFilter",
                      org.apache.shiro.web.servlet.IniShiroFilter.class)
              .addMappingForUrlPatterns(null, false, "/*");
  
      final WebApplicationContext context = getContext();
      servletContext.addListener(new ContextLoaderListener(context));
  
      final ServletRegistration.Dynamic dispatcher = servletContext.addServlet("DispatcherServlet", new DispatcherServlet(context));
      dispatcher.setLoadOnStartup(1);
      dispatcher.addMapping("*.do");
  }
  
  private AnnotationConfigWebApplicationContext getContext() {
      final AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
      context.register(AppConfig.class);
  
      return context;
  }
  }
  </code></pre>
  
  <p>My <code>web.xml</code> has the standard definitions for faces and the following mapping:</p>
  
  <pre><code>   .....
   &lt;context-param&gt;
      &lt;param-name&gt;javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE&lt;/param-name&gt;
      &lt;param-value&gt;true&lt;/param-value&gt;
  &lt;/context-param&gt;
     .....
   &lt;!-- JSF Mapping --&gt;
  &lt;servlet&gt;
      &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
      &lt;servlet-class&gt;javax.faces.webapp.FacesServlet&lt;/servlet-class&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
  &lt;/servlet&gt;
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
      &lt;url-pattern&gt;*.jsf&lt;/url-pattern&gt;
      &lt;url-pattern&gt;*.xhtml&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  </code></pre>
  
  <p>When the application starts up, I see output from Spring that is also duplicated! </p>
  
  <pre><code> 2013-12-12T11:29:56.430-0500|INFO: [org.springframework.web.context.support.AnnotationConfigWebApplicationContext]  - Refreshing Root WebApplicationContext: startup date [Thu Dec 12 11:29:56 EST 2013]; root of context hierarchy
  
   2013-12-12T11:29:56.430-0500|INFO: [org.springframework.web.context.support.AnnotationConfigWebApplicationContext]  - Refreshing Root WebApplicationContext: startup date [Thu Dec 12 11:29:56 EST 2013]; root of context hierarchy
  
   2013-12-12T11:29:56.978-0500|INFO: [org.springframework.context.annotation.ClassPathBeanDefinitionScanner]  - JSR-250 'javax.annotation.ManagedBean' found and supported for component scanning
  
   2013-12-12T11:29:56.978-0500|INFO: [org.springframework.context.annotation.ClassPathBeanDefinitionScanner]  - JSR-250 'javax.annotation.ManagedBean' found and supported for component scanning
  </code></pre>
  
  <p>How do I stop the duplicate calls?  Thanks.</p>
  
  <p><strong>EDIT</strong>
  I'm using Log4j.  Here's my configuration:</p>
  
  <pre><code>log4j.rootLogger=info, A1
  log4j.appender.A1=org.apache.log4j.ConsoleAppender
  log4j.appender.stdout.Target=System.out
  log4j.appender.A1.layout=org.apache.log4j.PatternLayout
  log4j.appender.A1.layout.ConversionPattern=[%c] %x - %m%n
  log4j.logger.org.hibernate=info, A1
  log4j.logger.com.telus=info, A1
  log4j.logger.org.springframework=info, A1
  </code></pre>
  
  <p>Using Spring 3.1.4.RELEASE.  PrimeFaces 4.0.  JSF 2.1.7. Deployed on Glassfish 3. Java 1.6.32.</p>