Proxy for a standard Servlet 2.3 Filter, delegating to a Spring-managed bean that implements the Filter interface. Supports a "targetBeanName" filter init-param in {@code web.xml}, specifying the name of the target bean in the Spring application context.
{@code web.xml} will usually contain a {@code DelegatingFilterProxy} definition,with the specified {@code filter-name} corresponding to a bean name inSpring's root application context. All calls to the filter proxy will then be delegated to that bean in the Spring context, which is required to implement the standard Servlet 2.3 Filter interface.
This approach is particularly useful for Filter implementation with complex setup needs, allowing to apply the full Spring bean definition machinery to Filter instances. Alternatively, consider standard Filter setup in combination with looking up service beans from the Spring root application context.
NOTE: The lifecycle methods defined by the Servlet Filter interface will by default not be delegated to the target bean, relying on the Spring application context to manage the lifecycle of that bean. Specifying the "targetFilterLifecycle" filter init-param as "true" will enforce invocation of the {@code Filter.init} and {@code Filter.destroy} lifecycle methodson the target bean, letting the servlet container manage the filter lifecycle.
As of Spring 3.1, {@code DelegatingFilterProxy} has been updated to optionally acceptconstructor parameters when using Servlet 3.0's instance-based filter registration methods, usually in conjunction with Spring 3.1's {@link org.springframework.web.WebApplicationInitializer} SPI. These constructors allowfor providing the delegate Filter bean directly, or providing the application context and bean name to fetch, avoiding the need to look up the application context from the ServletContext.
This class was originally inspired by Spring Security's {@code FilterToBeanProxy}class, written by Ben Alex.
@author Juergen Hoeller
@author Sam Brannen
@author Chris Beams
@since 1.2
@see #setTargetBeanName
@see #setTargetFilterLifecycle
@see javax.servlet.Filter#doFilter
@see javax.servlet.Filter#init
@see javax.servlet.Filter#destroy
@see #DelegatingFilterProxy(Filter)
@see #DelegatingFilterProxy(String)
@see #DelegatingFilterProxy(String,WebApplicationContext)
@see javax.servlet.ServletContext#addFilter(String,Filter)
@see org.springframework.web.WebApplicationInitializer