记一次SpringBoot Filter的过滤器被重复执行问题
debug发现过滤器 执行两次,后来定位到WebFilter和Component注解导致多次扫描,而这次需要用到WebFilter,所以注掉了Component
@Order(0)
//@Component
@WebFilter(urlPatterns = {"/*"})
@ConditionalOnProperty(name = "color.trace.start", havingValue = "true")
public class ThreadFilter implements Filter {
public ThreadFilter() {
System.out.println("color.trace.start...");
}
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse
servletResponse, FilterChain filterChain) throws IOException, ServletException {
String requestId = StrUtils.genRequestId();
ThreadLocalUtils.init(requestId);
MDC.put(MDC_TRACE_ID,requestId);
filterChain.doFilter(servletRequest, servletResponse);
ThreadLocalUtils.close();
}
@Override
public void destroy() {
}
}
@EnableColorProxy
@ServletComponentScan("com.player3.color.filter")
@SpringBootApplication
public class EshopOrderApplication {
public static void main(String[] args) {
SpringApplication.run(EshopOrderApplication.class, args);
}
}
b站视频:https://www.bilibili.com/video/BV11u411w7U3/
标签:SpringBoot,color,void,Filter,过滤器,WebFilter,public From: https://www.cnblogs.com/q1359720840/p/17690045.html