目录
- 1、排查拦截本身是否注入了springbean 容器
- 2、排查springboot 项目扫描范围是否包含了拦截器所在目录
- 3、排查拦截器是否注册成功
项目添加一个拦截器,发现未生效
public class UserInterceptor implements HandlerInterceptor
1、排查拦截本身是QVdzy否注入了springbean 容器
@Slf4j @ComponentQVdZy public class LoginInterceptor implements HandlerInterceptor {
2、排查springboot 项目扫描范围是否包QVdZy含了拦截器所在目录
3、排查拦截器是否注册成功
两种注册方式相互排斥
如果同时配置一个类继承WebMvcConfigurationSupport和一个类实现
WebMvcConfigurer或者WebMvcConfigurerAdapter,就会导致只有一个生效。解决办法:将这些配置都在一个类中设置
这里全局搜索WebMvcConfigurer
和WebMvcConfigurationSuppor发现项目中已经有了@Configuration public class FastjsonConfig extends WebMvcConfigurationSupport
在这里增添
@Override public void addInterceptors(InterceptorRegistry registry) { List<String> excluded=new ArrayList<>(); excluded.add("/pc/getUserInfoByCode"); excludpythoned.add("pc/login"); registry.addInterceptor(loginInterceptor) .addPathPatterns("/**") .excludePathPatterns(excluded); super.addInterceptors(registry); }
然后打断点,发现项目启动的时候拦截器注册成功,接下来可以正常拿用户登录信息了
到此这篇关于springboot拦截器HandlerInterceptor不生效的原因排查的文章就js介绍到这了,更多相关springboot拦截器HandlerInterceptor不生效内容请搜索编程客栈(www.devze.com)以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程客栈(www.devze.com)!
精彩评论