实现mvc拦截器需要继承spring提供的WebMvcConfigurationSupport类,并且重写其中的addInterceptors方法,将实现了HandlerInterceptor的类加入到addInterceptors中,即可实现对请求的拦截,代码如下
protected void addInterceptors(InterceptorRegistry registry){
log.info("开始注册自定义拦截器...");
registry.addInterceptor(jwtTokenInterceptor)
.addPathPatterns("/**")
.excludePathPatterns("/user/login")
.excludePathPatterns("/user/register")
.excludePathPatterns("/common/**").
excludePathPatterns("/user/changePassword");
}