Exclude Spring Request HandlerInterceptor by Path-Pattern

后端 未结 3 1254
借酒劲吻你
借酒劲吻你 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:19

    In my case:

    /api/v1/user-manager-service/tenants/add

    there was incorrect PathPattern configuration:

     @Override
        public void addInterceptors(InterceptorRegistry registry) {
            registry.addInterceptor(new RequestInterceptor())
                    .addPathPatterns("/**")
                    .excludePathPatterns("/tenants/**");
        }
    

    I was missing:

    /**

    before actual path.

    After correction it works as expected:

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new RequestInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/**/tenants/**");
    }
    

提交回复
热议问题