title: Spring Security without web.xml
body: <p>What is the recommended way to add Spring Security to a web application that is using Spring's new <code>WebApplicationInitializer</code> interface instead of the web.xml file?  I'm looking for the equivalent of:</p>
  
  <pre><code>&lt;filter&gt;
      &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
      &lt;filter-class&gt;org.springframework.web.filter.DelegatingFilterProxy&lt;/filter-class&gt;
  &lt;/filter&gt;
  </code></pre>
  
  <p><strong>UPDATE</strong> <br />
  The provided answers are reasonable but they both assume that I've got a <code>servletContext</code> instance.  I've looked through the hierarchy of <code>WebApplicationInitializer</code>s and I don't see any access to the servlet context unless I choose to override one of Spring's initializer methods.  <code>AbstractDispatcherServletInitializer.registerServletFilter</code> seems like the sensible choice but it doesn't default to URL pattern mapping and I'd hate to change filter registration for everything if there is a better way.</p>