解决Spring Security自定义filter重复执行问题
今天做项目的时候,发现每次拦截器日志都会打两遍,很纳闷,怀疑是Filter被执行了两遍。结果debug之后发现还真是!记录一下这个神奇的BUG! 问题描述 项目中使用的是Spring-security作为权限框架,然后做了一个 JwtAuthenticationTokenFilter 作为拦截器拦截请求,校验Token,但是每次请求都会打两遍日志。下面是精简的源代码: 自定义的Filter类 @Slf4j @Component public class JwtAuthenticationTokenFilter extends OncePerRequestFilter { @Override protected void doFilterInternal( HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws ServletException, IOException { //...省略 //打出两遍日志的地方 log.info("User:{} request path:{}, method:{}, param:{}", username, request.getServletPath(), request.getMethod(), request