web.xml:
myFilter
com.mypackage.MyFilter
Since Filter is not a spring bean(it is a web component) the injections won't work inside them. Springs wont inject inside web component.
use a DelegatingFilterProxy, this is a filter implementation that takes a springbean name as init param and delegates the filter request to that bean.
myFilter
org.springframework.web.filter.DelegatingFilterProxy
targetBeanName
myFilterBean
myFilter
/myFilterPattern/*
And create a Bean with name myFilterBean in your spring context.
public class MyFilter extends GenericFilterBean {
@Autowired
InjectedBean someInjectedBean;
@Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
chain.doFilter(request, response);
}
}