MVC Java Config - HandlerInterceptor not excluding paths

后端 未结 5 747
孤城傲影
孤城傲影 2021-02-07 15:37

I have a MVC Java configuration but the HandlerInterceptor is not excluding some patterns.

At the line marked with xxx, if

1) I ad

5条回答
  •  滥情空心
    2021-02-07 16:19

    I've faced a similar problem while working with SpringBoot.

    How I solved this problem?

    I made a method to return a new instance of the Interceptor. And you will have to write the excludePathPatters after the addPathPattern method of the registry.

    Here's the code snippet:

    @Bean
    public AuthInterceptor getAuthInterceptor() {
        return new AuthInterceptor();
    }
    
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(**getAuthInterceptor()**)
            .addPathPatterns("/**")
            .excludePathPatterns("/login/**");
    }
    

    I hope this helps.

提交回复
热议问题