方法一:
web.xml配置一个
<filter>
<filter-name>DelegatingFilterProxy</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
<init-param>
<param-name>targetBeanName</param-name>
<param-value>myFilter</param-value> //自己过滤器的名字
</init-param>
<init-param>
<param-name>targetFilterLifecycle</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>DelegatingFilterProxy</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
方法二:
web.xml配置一个
<filter>
<filter-name>myFilter</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>myFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
方法一或者二不同的地方就是在web.xml中的写法不同而已没有太大的区别,配完web.xml之后还要配置applicationContext.xml中的bean。
applicationContext.xml配置:
<bean id="myFilter" //指名具体的filter类
<property name="service"> //需要注入的具体参数
<ref bean="service"/>
</property>
</bean>
<bean id="service" parent="baseTransactionProxy">//这里的service封装了所有对数据库的操作
<property name="target">
<bean ......
</bean>
</property>
</bean>
本文介绍了两种在 Spring 应用中配置 DelegatingFilterProxy 的方法,一种是在 web.xml 中配置并映射到所有 URL,另一种是直接指定过滤器名称进行配置。此外,还详细说明了如何在 applicationContext.xml 中定义对应的 Bean。
1763

被折叠的 条评论
为什么被折叠?



