web Filter中使用spring注入的bean(转)

web Filter中使用spring注入的bean

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>DelegatingFilterProxy</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

配完web.xml之后还要配置 applicationContext.xml中的bean。

applicationContext.xml配置:

<bean id="myFilter" class="com.MyFilter"> //指名具体的filter类
    <property name="service">                    //需要注入的具体参数
        <ref bean="service"/>
    </property>
</bean> 

参见:http://blog.csdn.net/fzhlee/archive/2010/11/17/6014481.aspx

猜你喜欢

转载自lilywangcn.iteye.com/blog/1098762