Servlet过滤器中的弹簧注入 [英] spring injection in servlet filter

查看:65
本文介绍了Servlet过滤器中的弹簧注入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试对servlet过滤器进行弹簧注入.该过滤器是引用的jar文件的一部分.所以.我无法将其更改为拦截器.在我的插件项目的web.xml中

I am trying to do spring injection to servlet filter.The filter is apart of the referenced jar files. so. I cannot change it as interceptor. In web.xml of my plugin project

<filter>
    <filter-name>CustomFilter</filter-name>    
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>    
    <init-param>    
        <param-name>someinitparam</param-name>    
        <param-value>value to it</param-value>    
    </init-param>
</filter>
<filter-mapping>
    <filter-name>CustomFilter</filter-name>
    <url-pattern>/mywebservices/*</url-pattern>
</filter-mapping>

在spring.xml中,我将像这样使用

In spring.xml I will use like this

<bean id="CustomFilter" class="com.abc.CustomFilter"></bean>

spring.xml中已经将某些过滤器配置为

There are some filters are already configured in spring.xml as

<bean id="filterChainProxy" class="org.acegisecurity.util.FilterChainProxy">
    <property name="filterInvocationDefinitionSource">
        <value>
            CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
            PATTERN_TYPE_APACHE_ANT
            /mywebservices/*=some existing filters
        </value>              
    </property>
</bean>

因为我已经在web.xml中指定了我的网址格式,所以我需要在filterChainProxy中再次添加为

As I have already specified my url pattern in web.xml do I need to add again in filterChainProxy as

/mywebservices/**=CustomFilter, some existing filters

它将起作用.

请提出建议.

推荐答案

您可以像在web.xml中一样配置过滤器

You can configure the filter like you did in your web.xml

<filter>
   <filter-name>CustomFilter</filter-name>
   <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>

<filter-mapping>
   <filter-name>CustomFilter</filter-name>
   <url-pattern>/mywebservices/*</url-pattern>
</filter-mapping>

,然后在spring.xml中注入属性

and then inject properties in the spring.xml

<bean id="CustomFilter" class="com.abc.CustomFilter">
   <property name="someParameter">
      <value>some value</value>
   </property>
</bean>

这篇关于Servlet过滤器中的弹簧注入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆