弹簧启动中的过滤器顺序
2022-08-31 14:01:41
如何指定过滤器在弹簧启动中的顺序?我需要在Spring Security过滤器之后插入MDC过滤器。我几乎尝试了一切,但我的过滤器总是第一位的。这不起作用:
@Bean
@Order(Ordered.LOWEST_PRECEDENCE)
public UserInsertingMdcFilter userInsertingMdcFilter() {
return new UserInsertingMdcFilter();
}
这也不起作用:
@Bean
public FilterRegistrationBean userInsertingMdcFilterRegistrationBean() {
FilterRegistrationBean registrationBean = new FilterRegistrationBean();
UserInsertingMdcFilter userFilter = new UserInsertingMdcFilter();
registrationBean.setFilter(userFilter);
registrationBean.setOrder(Integer.MAX_VALUE);
return registrationBean;
}