title: Spring MVC InterceptorHandler called twice with DeferredResult
body: <p>When I am using custom <code>HandlerInterceptor</code> and my controller returns <code>DeferredResult</code>, the  <code>preHandle</code> method of my custom interceptor called twice on each request. Consider a toy example.</p>
  
  <p>My custom interceptor:</p>
  
  <pre><code>public class MyInterceptor implements HandlerInterceptor {
      static int i = 0;
  
      @Override
      public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
          System.out.println(i++);
          return true;
      }
  
      @Override
      public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
      }
  
      @Override
      public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
      }
  }
  </code></pre>
  
  <p>My Spring Java configuration:</p>
  
  <pre><code>@Configuration
  @EnableWebMvc
  public class ApplicationConfiguration extends WebMvcConfigurerAdapter {
  
      @Override
      public void addInterceptors(InterceptorRegistry registry) {
          registry.addInterceptor(new MyInterceptor());
      }
  }
  </code></pre>
  
  <p>My Controller:</p>
  
  <pre><code>@Controller
  public class MyController {
  
      @RequestMapping(value = "/test", method = RequestMethod.GET)
      public DeferredResult&lt;String&gt; test() {
          DeferredResult&lt;String&gt; df = new DeferredResult&lt;String&gt;();
          df.setResult("blank");
          return df;
      }
  }
  </code></pre>
  
  <p>So, on each page load I see two outputs from <code>preHandle</code> method. However, if I modify <code>MyController</code> in order to return just "blank" template (instead of <code>DeferredResult</code> with "blank" template), I see just one output from <code>preHandle</code> on each page load. </p>
  
  <p>So, my question is why <code>preHandle</code> called twice when I use <code>DeferredResult</code> and is it possible to avoid this?</p>