How to inject bean objects in your own filter in spring+spring mvc

Step 1: Add your own filter to application.xml
Insert picture description here
Step 2: Configure filter in web.xml, which is a bit different from the previous configuration! ! !

<!--  主的filter-->
  <filter>
    <filter-name>indexFilter</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    <init-param>
      <param-name>targetFilterLifecycle</param-name>
      <param-value>true</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>indexFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

The filter-class is the fixed org.springframework.web.filter.DelegatingFilterProxy
filter-name is the same as the id of the bean configured in application.xml!
I hope I won't do it again! ! ! ! !

Guess you like

Origin blog.csdn.net/weixin_44061648/article/details/103602407