title: How to configure Spring Security with already existing WebApplicationInitializer?
body: <p>I am doing a web site project with Spring/ Spring MVC I learned how to configure a spring with the java classes and annotations approach, which by far is better than the XML. </p>
  
  <p>Now I want to use Spring Security with my application. However I could not understand how to configure it with already existing <code>WebApplicationInitializer</code> ? </p>
  
  <p><a href="http://docs.spring.io/spring-security/site/docs/4.0.0.M2/reference/htmlsingle/#jc" rel="nofollow">The Spring documentation</a> is not so clear.</p>
  
  <p>Here is my code and what I have so far: </p>
  
  <pre><code>public class AppInitializer implements WebApplicationInitializer{
  //public class AppInitializer {
  
  
      private static final Class&lt;?&gt;[] CONFIG_CLASSES = new Class&lt;?&gt;[]{SiteConfigs.class, AdminConfigurations.class};
  
      public void onStartup(ServletContext servletContext) throws ServletException {
  
          AnnotationConfigWebApplicationContext appContext = new AnnotationConfigWebApplicationContext();
          appContext.register(CONFIG_CLASSES);
  
          DispatcherServlet servlet = new DispatcherServlet(appContext);
          ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", servlet);
          dispatcher.setLoadOnStartup(1);
          dispatcher.addMapping("/");
  
      }
  
  }
  </code></pre>
  
  <p>If I add <code>AbstractSecurityWebApplicationInitializer</code> to the classpath the container throws 
   exception.</p>
  
  <pre><code>HTTP Status 500 - No WebApplicationContext found: no ContextLoaderListener registered?  
  </code></pre>
  
  <p>So how to config Spring Security so that <code>springSecurityFilterChain</code> get initialized</p>