Shiro_DelegatingFilterProxy

1.DelegatingFilterProxy实际上是Filter的一个代理对象。默认情况下,Spring会到IOC容器中查找与<filter-name>对应的filter bean。也可以通过targetBeanName的初始化参数来配置bean的id。

 

2.配置shiroFilter

--id必须和web.xml文件中配置的DelegatingFilterProxy的<filter-name>一致。为什么?(看下文)
--若不一致,则会抛出异常。因为Shiro会来IOC容器寻找与<filter-name>名字对应的filter Bean

 

(1)查看org.springframework.web.filter.DelegatingFilterProxy的源码,

 

1     /**
2      * Return the name of the ServletContext attribute which should be used to retrieve the
3      * {@link WebApplicationContext} from which to load the delegate {@link Filter} bean.
4      */
5     public String getContextAttribute() {
6         return this.contextAttribute;
7     }

 

1     /**
2      * Set the name of the target bean in the Spring application context.
3      * The target bean must implement the standard Servlet Filter interface.
4      * <p>By default, the {@code filter-name} as specified for the
5      * DelegatingFilterProxy in {@code web.xml} will be used.
6      */
7     public void setTargetBeanName(String targetBeanName) {
8         this.targetBeanName = targetBeanName;
9     }

 

(2)做以下调整,

web.xml:

 

applicationContext.xml:

 

结果:可以正常运行。

 

posted @ 2018-09-20 17:38  猩生柯北  阅读(157)  评论(0编辑  收藏  举报