1.问题
在过滤器里,注解添加了拦截指定的URL ,但是拦截器依然拦截所有的请求:
@WebFilter(filterName = "authInterceptor", value = "/openApi/*" ) @Order(1)
@Component public class AuthInterceptor implements Filter { @Override public void init(FilterConfig filterConfig) throws ServletException { } @Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest)servletRequest; HttpServletResponse response = (HttpServletResponse)servletResponse; String url = request.getServletPath(); logger.info("[interceptor] url:" + url); chain.doFilter(requestWrapper != null ? requestWrapper :request,response); } @Override public void destroy() { } }
2.问题解决
去掉 Component注解,改用在启动类添加 @ServletComponentScan
亲测起作用