title: What's the point of Spring MVC's DelegatingFilterProxy?
body: <p>I see this in my Spring MVC app's <code>web.xml</code>:</p>
  
  <pre class="lang-xml prettyprint-override"><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>I'm trying to figure out why it's there and whether it's actually needed.</p>
  
  <p>I found <a href="http://static.springsource.org/spring-security/site/docs/3.0.x/reference/security-filter-chain.html" rel="noreferrer">this explanation in the Spring docs</a> but it doesn't help me make sense of it:</p>
  
  <p>It seems to suggest that this component is the "glue" between the servlets defined in <code>web.xml</code> and the components defined in the Spring <code>applicationContext.xml</code>.</p>
  
  <blockquote>
    <p>7.1 DelegatingFilterProxy</p>
    
    <p>When using servlet filters, you obviously need to declare them in your <code>web.xml</code>, or they will be ignored by the servlet container. In Spring Security, the filter classes are also Spring beans defined in the application context and thus able to take advantage of Spring's rich dependency-injection facilities and lifecycle interfaces. Spring's <code>DelegatingFilterProxy</code> provides the link between <code>web.xml</code> and the application context.</p>
    
    <p>When using DelegatingFilterProxy, you will see something like this in the <code>web.xml</code> file:</p>
    
    <pre class="lang-xml prettyprint-override"><code>&lt;filter&gt;
     &lt;filter-name&gt;myFilter&lt;/filter-name&gt;
     &lt;filter-class&gt;org.springframework.web.filter.DelegatingFilterProxy&lt;/filter-class&gt;
  &lt;/filter&gt;
  
  &lt;filter-mapping&gt;
     &lt;filter-name&gt;myFilter&lt;/filter-name&gt;
     &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
  &lt;/filter-mapping&gt;
  </code></pre>
    
    <p>Notice that the filter is actually a <code>DelegatingFilterProxy</code>, and not the class that will actually implement the logic of the filter. What <code>DelegatingFilterProxy</code> does is delegate the Filter's methods through to a bean which is obtained from the Spring application context. This enables the bean to benefit from the Spring web application context lifecycle support and configuration flexibility. The bean must implement <code>javax.servlet.Filter</code> and it must have the same name as that in the filter-name element. Read the <a href="http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/web/filter/DelegatingFilterProxy.html" rel="noreferrer">Javadoc for DelegatingFilterProxy</a> for more information</p>
  </blockquote>
  
  <p>So, if I take this out of my <code>web.xml</code>, what will happen? My servlets won't be able to communicate with the Spring container?**</p>