Spring如何使用init-param值连接OncePerRequestFilter?

Han*_*Gay 4 web.xml spring-mvc

我有一个简单的在我的中定义OncePerRequestFilter了几个init-param条目web.xml,但我不知道如何从过滤器中访问它们.getFilterConfig()回报null.该init(FilterConfig)文档使它听起来像它会根据的名字做注射到bean的属性init-param,例如,一个名为PARAM foo将有它的价值注入上指定的过滤器的属性foo,但一些伐木doFilterInternal似乎表明,情况并非如此.

由于我对现代Spring相当新(最后一次使用它大约是1.x天)并且对于Spring MVC来说是全新的,我很确定我错过了一些明显的东西,但我看不出它是什么.谢谢你的帮助.

Gar*_*vis 5

这些init-param值映射到它自己的过滤器的属性.

public MyFilter extends OncePerRequestFilter {

    // the following should be called once the `GenericFilterBean` `init` method has run        
    public void setFoo(String foo){
         this.foo = foo;
    }
}


<filter>
     <init-param>
          <param-name>foo</param-name>
          <param-value>bar</param-value>
     </init-param>
</filter>
Run Code Online (Sandbox Code Playgroud)