过滤器Filter中注入类Bean

DelegatingFilterProxy管理过滤器

DelegatingFilterProxy提供了在 web.xml和application context之间的联系

FilterChainProxy过滤器链

这是一种繁琐的方式,会让web.xml显得十分杂乱,如果我们配置了太多过滤器的话。 我们最好添加一个单独的入口,在web.xml中,然后在application context中处理实体, 管理我们的web安全bean。 这就是FilterChainProxy所做的事情。


web.xml配置

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
    /WEB-INF/character-context.xml
            /WEB-INF/spring-configuration/*.xml
            /WEB-INF/deployerConfigContext.xml
           
            classpath*:/META-INF/spring/*.xml
        </param-value>
  </context-param>
  
  <listener>   
        <listener-class>   
            org.springframework.web.context.ContextLoaderListener   
        </listener-class>   
    </listener>  

<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>


character-context.xml配置

<bean id="cpc" class="com.chinamobile.cmss.sso.web.filter.CustomizedPropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>/WEB-INF/cas.properties</value>
</list>
</property>
<property name="fileEncoding" value="utf-8" />
</bean>

<bean id="myFilter" class="com.chinamobile.cmss.sso.web.filter.CrossDomainFilter">  原始的过滤器,继承Filter
<property name="cpc">
<ref bean="cpc"/>
</property>
</bean>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值