Exclude Spring Request HandlerInterceptor by Path-Pattern

后端 未结 3 1245
借酒劲吻你
借酒劲吻你 2021-02-14 17:39

I know we can map different url to different interceptor, or we can map multiple url to single interceptor too. I am just curious to know if we also have exclude option. for exa

3条回答
  •  别跟我提以往
    2021-02-14 18:31

    HandlerInterceptors can be applied or excluded to (multiple) specific url's or url-patterns.

    See the MVC Interceptor Configuration.

    Here are the examples from the documentation

    @Configuration
    @EnableWebMvc
    public class WebConfig extends WebMvcConfigurerAdapter {
    
        @Override
        public void addInterceptors(InterceptorRegistry registry) {
            registry.addInterceptor(new LocaleInterceptor());
            registry.addInterceptor(new ThemeInterceptor()).addPathPatterns("/**").excludePathPatterns("/admin/**");
    
            // multiple urls (same is possible for `exludePathPatterns`)
            registry.addInterceptor(new SecurityInterceptor()).addPathPatterns("/secure/*", "/admin/**", "/profile/**");
        }
    }
    

    or using XML config

    
        
        
            
            
            
        
        
            
            
            
            
            
        
    
    

提交回复
热议问题