Spring Filter not getting invoked

后端 未结 1 497
慢半拍i
慢半拍i 2021-01-23 13:50

I added a CORS filter to my application, but it does not seem to be executed (no prints).

The filter is this:

@Component
public class SimpleCORSFilter ex         


        
相关标签:
1条回答
  • 2021-01-23 14:31

    First, it is uncommon to name the Root Spring Container xml file servlet-context.xml. This name is normally used for the DispatcherServlet configuration when using spring-mvc. You'd better use applicationContext.xml.

    But anyway, you should use a DelegatingProxyFilter to allow proper initialization of the spring filter :

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

    The DelegatingProxyFilter will search in root context a bean named simpleCORSFilter and will delegate the doFilter method to it.

    0 讨论(0)
提交回复
热议问题