- Make the servlet filter implement the spring Ordered interface.
- Declare the servlet filter bean manually in configuration class.
import org.springframework.core.Ordered;
public class MyFilter implements Filter, Ordered {
@Override
public void init(FilterConfig filterConfig) {
// do something
}
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
// do something
}
@Override
public void destroy() {
// do something
}
@Override
public int getOrder() {
return -100;
}
}
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@Configuration
@ComponentScan
public class MyAutoConfiguration {
@Bean
public MyFilter myFilter() {
return new MyFilter();
}
}