Home Spring interceptor not working for partial REST endpoints
Reply: 0

Spring interceptor not working for partial REST endpoints

user1601 Published in June 20, 2018, 10:55 pm

I have a Spring Boot application with REST endpoints defined like this


I have created a Spring Interceptor to intercept all incoming request with following pattern

public void addInterceptors(InterceptorRegistry registry) {
   registry.addInterceptor(new RequestInterceptor()).addPathPatterns("/usermanagement/v1/**");


public class RequestInterceptor extends HandlerInterceptorAdapter {

    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
        throws Exception {
        return true;

    public void postHandle(
        HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView)
        throws Exception {
        System.out.println("This is Post Handling the request");

This interceptor works only if client accesses the complete endpoint i.e


In case a partial endpoint is accessed,


interceptor is not called and a 404 is returned to the client.

Is there a way to change this behavior? The reason I am doing this is because I don't want to expose specific endpoints but common endpoints and make internal calls to services and return result through common endpoints.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.313365 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO