JWT入门1 (2)

自定义Iterceptor实现WebMvcConfigurer重写addInterceptors(InterceptorRegistry)

@Configuration
public class MVCInterceptorConfiguration  implements WebMvcConfigurer {

    @Autowired
    private TokenInterceptor  tokenInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(tokenInterceptor).addPathPatterns("/**")
                .excludePathPatterns(
                        "/api-docs/**",
                        "/user/login",
                );
    }
}
 

    addInterceptor设置自定义拦截规则

    excludePathPatterns中设置的接口路径直接放行不验证token

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zwxydz.html