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
I think in spring-boot 2.0 version, this have changed a lot right now. Below is the implementation you can easily add and configure the path pattern.
@Component
public class ServiceRequestAppConfig implements WebMvcConfigurer {
@Autowired
ServiceRequestInterceptor sri;
@Override
public void addInterceptors(InterceptorRegistry registry) {
String pathPattern = "/admin/**";
registry.addInterceptor(sri).excludePathPatterns(pathPattern);
}
}
@Component
public class ServiceRequestInterceptor extends HandlerInterceptorAdapter {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
// Your logic
return true;
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable Exception ex){
// Some useful techniques
}
}