open class DelegatingFilterProxy : GenericFilterBean
Proxy for a standard Servlet Filter, delegating to a Spring-managed bean that implements the Filter interface. Supports a "targetBeanName" filter init-param in web.xml
, specifying the name of the target bean in the Spring application context.
web.xml
will usually contain a DelegatingFilterProxy
definition, with the specified filter-name
corresponding to a bean name in Spring'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 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 Filter.init
and Filter.destroy
lifecycle methods on the target bean, letting the servlet container manage the filter lifecycle.
As of Spring 3.1, DelegatingFilterProxy
has been updated to optionally accept constructor parameters when using Servlet 3.0's instance-based filter registration methods, usually in conjunction with Spring 3.1's org.springframework.web.WebApplicationInitializer SPI. These constructors allow for 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 FilterToBeanProxy
class, written by Ben Alex.
Author
Juergen Hoeller
Author
Sam Brannen
Author
Chris Beams
Since
1.2
See Also
#setTargetBeanName#setTargetFilterLifecyclejavax.servlet.Filter#doFilterjavax.servlet.Filter#initjavax.servlet.Filter#destroy#DelegatingFilterProxy(Filter)#DelegatingFilterProxy(String)#DelegatingFilterProxy(String, WebApplicationContext)javax.servlet.ServletContext#addFilter(String, Filter)org.springframework.web.WebApplicationInitializer
DelegatingFilterProxy()
Create a new DelegatingFilterProxy(delegate: Filter)
Create a new For use in Servlet 3.0+ environments where instance-based registration of filters is supported. DelegatingFilterProxy(targetBeanName: String)
Create a new For use in Servlet 3.0+ environments where instance-based registration of filters is supported. The target bean must implement the standard Servlet Filter. DelegatingFilterProxy(targetBeanName: String, wac: WebApplicationContext)
Create a new For use in Servlet 3.0+ environments where instance-based registration of filters is supported. The target bean must implement the standard Servlet Filter interface. The given This proxy's |
open fun destroy(): Unit |
|
open fun doFilter(request: ServletRequest, response: ServletResponse, filterChain: FilterChain): Unit |
|
open fun getContextAttribute(): String
Return the name of the ServletContext attribute which should be used to retrieve the WebApplicationContext from which to load the delegate Filter bean. |
|
open fun setContextAttribute(contextAttribute: String): Unit
Set the name of the ServletContext attribute which should be used to retrieve the WebApplicationContext from which to load the delegate Filter bean. |
|
open fun setTargetBeanName(targetBeanName: String): Unit
Set the name of the target bean in the Spring application context. The target bean must implement the standard Servlet Filter interface. By default, the |
|
open fun setTargetFilterLifecycle(targetFilterLifecycle: Boolean): Unit
Set whether to invoke the Default is "false"; target beans usually rely on the Spring application context for managing their lifecycle. Setting this flag to "true" means that the servlet container will control the lifecycle of the target Filter, with this proxy delegating the corresponding calls. |