0
votes

I am trying to inject dependency into a servlet filter by using spring bean:

I define the filter in web.xml:

<filter>
  <filter-name>myFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
  <filter-name>myFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

And I inject an instance in another bean section in ***-***-context.xml:

<bean id="myFilter" class="com.filter.MyFilter">
  <property name="runPolicy" ref="RunPolicy"/>
</bean>

<bean id="RunPolicy" class="com.***.***.RunPolicyImpl"/>

However, I got error:

failed myFilter: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'myFilter' is defined

What I am missing? Thank you!

P.S. I have spring listener and context-param in the web.xml

1

1 Answers

0
votes

I think the .xml file you are using for declaring the beans in not in classpath. Did you import your *****-*-context.xml in applicationContext.xml.