web.xml:
<filter>
<filter-name>myFilter</filter-name>
<filter-class>com.mypackage.MyFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>myFilter</filter-name>
<url-pattern>/myFilterPattern/*</url-pattern>
</filter-mapping>
MyFilter:
public class MyFilter implements Filter {
@Autowired
InjectedBean someInjectedBean;
However, when intercepting /myFilterPattern/*
requests, someInjectedBean
in MyFilter.doFilter(...)
is still null, meaning it has not been injected. The same bean (InjectedBean
) is injected fine in other context components that are not referenced in web.xml.
Is it because container filtering takes place outside the Spring context? Is there any way to have Spring injection in Filter implementation mapped in web.xml?