Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spring injection in servlet filter [duplicate]

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>

In spring.xml I will use like this

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

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>

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

Will it work.

Please suggest.

like image 946
Patan Avatar asked Feb 08 '13 05:02

Patan


1 Answers

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>

and then inject properties in the spring.xml

<bean id="CustomFilter" class="com.abc.CustomFilter">
   <property name="someParameter">
      <value>some value</value>
   </property>
</bean>
like image 76
ckoidl Avatar answered Oct 01 '22 17:10

ckoidl