Springboot添加拦截器配置excludePathPatterns不生效

 // 拦截所有请求,通过判断token是否合法来决定是否需要登录
        registry.addInterceptor(jwtInterceptor()).
                addPathPatterns("/**").
                excludePathPatterns(
                        "/api/sysUser/login",
                        "/api/sysUser/register",
                        "/**/export",
                        "/**/import",
                        "/**/file/**",
                        "/swagger-resources/**",
                        "/webjars/**",
                        "/v2/**",
                        "/swagger-ui.html/**"
//                        , "/error"
                );

一开始进行文件上传测试,报错出现以后,最后还是提示 无token

System.out.println(request.getRequestURL());

发现被拦截的是 /error;

代码有bug触发了错误,这时路径被重定向为**/error,由于**/error不在excludePathPatterns中所以会被拦截器拦截。

 

posted @ 2023-03-01 16:21  唏嘘-  阅读(819)  评论(0编辑  收藏  举报