Spring Framework filter, bean not injected

前端 未结 1 730
陌清茗
陌清茗 2021-01-02 20:57

There are 2 entries for a Servlet Filter, one in web.xml and one in Spring applicationContext.xml

I added the filter into applicationContext.xml because I wanted to

相关标签:
1条回答
  • 2021-01-02 21:30

    You can't make a Filter spring managed like this. With your setup it is instantiated once by spring, and once by the servlet container. Instead, use DelegatingFilterProxy:

    1. declare the filter proxy as a <filter> in web.xml
    2. Set the targetBeanName init-param of the filter definition to specify the bean that should actually handle the filtering:

      <init-param>
          <param-name>targetBeanName</param-name>
          <param-value>creditFilter</param-value>
      </init-param>
      
    0 讨论(0)
提交回复
热议问题