org.springframework.web.filter.DelegatingFilterProxy 淩亂°似流年 2022-02-15 01:14 155阅读 0赞 详情可以参考[https://blog.csdn.net/z69183787/article/details/23173093][https_blog.csdn.net_z69183787_article_details_23173093] 博客 背景描述: 项目需要一个过滤器,过滤一些请求,于是写完,但是需要过滤一些路径不走filter,于是根据这个 [https://www.cnblogs.com/hubing/p/6142072.html][https_www.cnblogs.com_hubing_p_6142072.html] 写完了 然后配置在web.xml <filter> <filter-name>testFilter</filter-name> <filter-class>com.ustb.TestFilter</filter-class> <init-param> <param-name>excludedUrls</param-name> <param-value>/test/1,/test/2</param-value> </init-param> </filter> <filter-mapping> <filter-name>testFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> 由于TestFilter这个类被注册成了bean,所以上面这种配置,TestFilter这个类的bean注入不进来, 根据这篇文章解决问题:[https://blog.csdn.net/z69183787/article/details/23173093][https_blog.csdn.net_z69183787_article_details_23173093] web.xml的配置要改成下面这样 <filter> <filter-name>TestFilter</filter-name> <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> <init-param> <param-name>targetFilterLifecycle</param-name> <param-value>true</param-value> </init-param> <init-param> <param-name>excludedUrls</param-name> <param-value>/test/1,/test/2</param-value> </init-param> </filter> <filter-mapping> <filter-name>encryptionAndDecryptionFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> **注意要添加targetFilterLifeCycle这个属性,这样过滤器初始化才有效!!!** [https_blog.csdn.net_z69183787_article_details_23173093]: https://blog.csdn.net/z69183787/article/details/23173093 [https_www.cnblogs.com_hubing_p_6142072.html]: https://www.cnblogs.com/hubing/p/6142072.html
还没有评论,来说两句吧...