DelegatingFilterProxy 快来打我* 2022-07-14 09:54 53阅读 0赞 最近在学习spring security的过程中,对spring-web包下的这个类 > org.springframework.web.filter.DelegatingFilterProxy 的作用很是疑惑,遂打算看下官方文档,译文如下: org.springframework.web.filter Class DelegatingFilterProxy ***继承关系:*** java.lang.Object org.springframework.web.filter.GenericFilterBean org.springframework.web.filter.DelegatingFilterProxy ***实现的接口 :*** All Implemented Interfaces: Filter, Aware, BeanNameAware, DisposableBean, InitializingBean, EnvironmentAware, ServletContextAware ***类定义:*** public class DelegatingFilterProxy extends GenericFilterBean ***官方文档类解析如下:*** Proxy for a standard Servlet Filter, delegating to a Spring-managed bean that implements the Filter interface. ***标准的servlet过滤器代理,委托给spring管理的实现了Filter接口的bean。*** Supports a “targetBeanName” filter init-param in web.xml, specifying the name of the target bean in the Spring application context. ***支持通过在web.xml中配置目标bean的名字,来指定出在spring环境中目标bean的名字*** web.xml will usually contain a DelegatingFilterProxy definition, with the specified filter-name corresponding对应的 to a bean name in Spring’s root application context. ***所有对这个过滤器代理的调用,都会被转到spring环境中的那个bean来处理*** 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. ***这个途径对需要复杂设置的过滤器是非常有用的,在这个过滤器实例里面可以使用全部spring定义的bean。要不然,就需要将实例化spring中的bean的过程整合在过滤器设置中。*** 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. ***注:通过上述的翻译,觉得最有用的一句话就是:allowing to apply the full Spring bean definition machinery to Filter instances,即在这个过滤器实例里面可以使用全部spring定义的bean。也就是说,通过使用DelegatingFilterProxy来对过滤器进行代理,可以是过滤器链和spring上下文环境结合起来,让spring来完成过滤器中依赖的bean的管理和注入,极大简化过滤器链的配置。*** ***这里推荐一个文章,感觉很有用,但是我没看懂:[http://wangqiaowqo.iteye.com/blog/1139408][http_wangqiaowqo.iteye.com_blog_1139408]*** ***下面的有空再翻译*** 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 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. [http_wangqiaowqo.iteye.com_blog_1139408]: http://wangqiaowqo.iteye.com/blog/1139408
相关 DelegatingFilterProxy 最近在学习spring security的过程中,对spring-web包下的这个类 > org.springframework.web.filter.DelegatingF 快来打我*/ 2022年07月14日 09:54/ 0 赞/ 54 阅读
相关 Spring Web学习--DelegatingFilterProxy 代理Filter Spring web在设计的时候考虑到某些功能的实现是通过Filter来拦截进行实现的,如果直接的简单的实现几个Filter好像也不是不可以(平时我们就是这么用的 迷南。/ 2022年05月17日 12:08/ 0 赞/ 118 阅读
相关 org.springframework.web.filter.DelegatingFilterProxy 详情可以参考[https://blog.csdn.net/z69183787/article/details/23173093][https_blog.csdn.net_z69 淩亂°似流年/ 2022年02月15日 01:14/ 0 赞/ 155 阅读
相关 spring之DelegatingFilterProxy DelegatingFilterProxy是一个标准servlet Filter的代理,代理实现了Filter接口的spring管理的Bean。支持一个在web.xml的ini 系统管理员/ 2021年06月11日 15:11/ 0 赞/ 331 阅读
还没有评论,来说两句吧...