zoukankan      html  css  js  c++  java
  • 过滤器设置了拦截的URL,却依然拦截所有请求

    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

     亲测起作用

    stay hungry stay foolish!
  • 相关阅读:
    预防新型冠状病毒科普宣传网站
    四则运算
    结对审查
    最大子段和
    单元自动测试Junit
    浅谈过去,畅想未来
    第一次的结对编程
    代码审查
    单元测试
    junit4单元测试
  • 原文地址:https://www.cnblogs.com/shog808/p/14980436.html
Copyright © 2011-2022 走看看