SpringBoot2 Filter执行两次问题解决

@Configuration
public class MyFilterConfig {

@Bean(name="sysVisitFilter")
public SysVisitFilter sysVisitFilter(){
return new SysVisitFilter();
}

@Bean
public FilterRegistrationBean sysVisitFilterBean() {
FilterRegistrationBean registrationBean = new FilterRegistrationBean();
registrationBean.setFilter(new DelegatingFilterProxy("sysVisitFilter"));
registrationBean.addInitParameter("targetFilterLifecycle","true");
registrationBean.addUrlPatterns("/*");
registrationBean.addInitParameter("exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.ico");
registrationBean.setDispatcherTypes(DispatcherType.REQUEST);
// 一定要设置false 否则过滤器执行两次
registrationBean.setEnabled(false);
return registrationBean;
}
}

上一篇:【第51题】【062题库】2019年OCP认证062考试新题


下一篇:springcloud -hystrix-dashboard填坑