Results 1 to 3 of 3

Thread: Using DelegatingFilterProxy with autowired dependency

  1. #1
    Join Date
    May 2011
    Posts
    4

    Question Using DelegatingFilterProxy with autowired dependency

    Hi,

    I have a filter defined in web.xml as
    Code:
    <filter>
            <filter-name>sampleSpringFilter</filter-name>
            <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
        </filter>
        
        <filter-mapping>
    		<filter-name>sampleSpringFilter</filter-name>
    		<url-pattern>/api/foo/*</url-pattern>
        </filter-mapping>
    The class sampleSpringFilter is defined as:
    Code:
    @Component("sampleSpringFilter")
    public class SampleSpringFilter implementes Filter
    {
    
      @Inject
      private ITestService testService;
    
     @Override
    	public void doFilter(ServletRequest request, ServletResponse response,
    			FilterChain chain) throws IOException, ServletException {
    --
    }
    }
    When I am trying to deploy my webapp in tomcat 7, application context is not able to find sampleSpringFilter.
    I don't want to use xml based bean definition for sampleSpringFilter.

    Please help me resolving this issue.
    Last edited by omanand; Oct 25th, 2012 at 12:29 AM.

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    Please use [ code][/code ] tags when posting code/xml/stacktraces, that way it remains readable...

    Only specifing the filter and adding @Component is pretty useless... If you don't scan for components (component-scanning) nothing is going to happen. Also the compoment has to be in the root context (ContextLoaderListener) and not in the child context (DispatcherServlet).
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    May 2011
    Posts
    4

    Default

    Thanks Marten. I had made a mistake of specifying component-scan in the child context (DispatcherServlet).

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •