title: Why doesn't DispatcherServlet invoke my HandlerInterceptor?
body: <p>I know that in JavaEE, filters can intercept any request to a servlet. But Interceptors in Spring MVC are not exactly the same. If you look at the diagram below, you will see that Interceptors come after Dispatcher Servlet. </p>
  
  <p>Let me give you an example before I ask my question. </p>
  
  <p>I have a controller, which has 2 methods in it that are mapped to two different requests. One accepts GET requests and other accepts POST requests. Now if I add an interceptor in my web application, that interceptor will sit before Controller. Meaning that before controller method is hit, first a <code>request</code> will hit my interceptor's <code>preHandle</code> method. </p>
  
  <p>Now say that in my app, two controllers methods look like this: </p>
  
  <pre><code>@Controller
  public class myController{
  
  @RequestMapping(value = "/test", method = RequestMethod.GET)
  public String test1(){      
      return "abc";
  }
  
  @RequestMapping(value = "/login", method = RequestMethod.POST)
  public String test1(){      
      return "xyz";
  }
  </code></pre>
  
  <p>And lets say I have a simple interceptor like this:</p>
  
  <pre><code>public class URLInterceptors extends HandlerInterceptorAdapter  {
  
      @Override
      public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
          System.out.println("REQUESTED SERVLET PATH IS: " + request.getServletPath());   
          return true;    
      }   
  }
  </code></pre>
  
  <p>Now, if I make a GET request to <code>/test</code>, my interceptor is hit and it prints the servlet path, but when I make a <code>GET</code> request to <code>/login</code>, I know it will fail because my method that handles <code>/login</code> mapping accepts only <code>POST</code> requests, however before it throws '405 Request method 'GET' not supported' error, it should at least hit first my interceptor? It doesn't. I I don't want to change <code>POST</code> to <code>GET</code>. So the question is why?  </p>
  
  <p><a href="https://i.stack.imgur.com/huiyV.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/huiyV.jpg" alt="enter image description here"></a></p>