美文网首页
springboot 拦截器

springboot 拦截器

作者: 我喝岩浆 | 来源:发表于2020-05-27 10:26 被阅读0次

    拦截器定义

    @Configuration
    @AllArgsConstructor
    public class InterceptorConfig extends WebMvcConfigurationSupport {
    
        @Autowired
        private MyHttpInterceptor myHttpInterceptor;
    
      
        @Override
        public void addInterceptors(InterceptorRegistry registry) {
            registry.addInterceptor(myHttpInterceptor).addPathPatterns("/**")
                    .excludePathPatterns("/user/login")
                  //避免swagger 打不开
                    .excludePathPatterns("/swagger-resources/**", "/webjars/**", "/v2/**", "/swagger-ui.html/**");;
        }
        @Override
        protected void addResourceHandlers(ResourceHandlerRegistry registry) {
            registry.addResourceHandler("swagger-ui.html")
                    .addResourceLocations("classpath:/META-INF/resources/");
            registry.addResourceHandler("/webjars/**")
                    .addResourceLocations("classpath:/META-INF/resources/webjars/");
        }
    }
    

    相关文章

      网友评论

          本文标题:springboot 拦截器

          本文链接:https://www.haomeiwen.com/subject/dxoiahtx.html