學習了這幾節Shiro可能,也許大家對DelegatingFilterProxy還不是很瞭解,其實有一些東西需要去注意,防止在項目中出現這種低級的錯誤。
首先在web.xml中是這樣配置的。
<filter>
<filter-name>shiroFilter</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>
</filter>
<filter-mapping>
<filter-name>shiroFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
filter-name的值相當於給org.springframework.web.filter.DelegatingFilterProxy起了一個別名,但是呢需要注意的是需要和applicationContext.xml中的id一致,即:
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
.....
.....
<bean/>
不一致則報錯:
原因:Filter在進行初始化的時候,會先找和會到 IOC 容器中查找和 <filter-name> 對應的 filter bean,通過getBean方法就獲取到了applicationContext.xml中對應的filter詳細的結果請查看源碼進行打斷點測試。