Spring, Interceptor's excludePathPatterns function is not working properly

java, spring-mvc

Solution

Have you tried as below?

@Configuration
@EnableWebMvc
public class MyWebConfig extends WebMvcConfigurerAdapter 
{
  @Override
  public void addInterceptors(InterceptorRegistry registry) 
  {
    registry.addInterceptor(new MyCustomInterceptor())
            .addPathPatterns("/**")
            .excludePathPatterns("/foo/**");
  }
}

Reference

Refer this java doc for better understanding.

Problem

I am working on Spring Framework and I wanted to write an interceptor and I wrote it eventually and it is working fine. but at a point, I dont want my interceptor to intercept the request that is when user wants to logout and the session is being invalidated. But it is not happening as per my expectation. I am adding interceptors by extending the WebMvcConfigurerAdapter and by utilizing the addInterceptors method and here is the code. ``` public void addInterceptors(InterceptorRegistry registry) { super.addInterceptors(registry); registry.addInterceptor( loggerInterceptor ); registry.addInterceptor( authenticationInterceptor ).excludePathPatterns("/invalidate"); } ``` Have I done anything wrong here.? excludePathPatterns - > My URL ends with /invalidate. So please guide me, how to device a proper pattern.

Original source