title: How to handle HTTP OPTIONS requests in Spring Boot?
body: <p>First off, I've read "<a href="https://stackoverflow.com/q/9521690/56285">How to handle HTTP OPTIONS with Spring MVC?</a>" but the answers do not seem directly applicable to Spring Boot.</p>
  
  <p>It looks like I should do this:</p>
  
  <blockquote>
    <p>configure the dispatcherServlet by setting its
    <code>dispatchOptionsRequest</code> to <code>true</code></p>
  </blockquote>
  
  <p><strong>But how to do that</strong>, given that I have no XML configs, or any variety of <code>DispatcherServlet</code> initializer class in my code (<a href="https://stackoverflow.com/a/15761692/56285">mentioned by this answer</a>)?</p>
  
  <p>In a <code>@RestController</code> class, I have a method like this, which currently does not get invoked.</p>
  
  <pre><code>@RequestMapping(value = "/foo", method = RequestMethod.OPTIONS)
  public ResponseEntity options(HttpServletResponse response) {
      log.info("OPTIONS /foo called");
      response.setHeader("Allow", "HEAD,GET,PUT,OPTIONS");
      return new ResponseEntity(HttpStatus.OK);
  }
  </code></pre>
  
  <p>Spring Boot 1.2.7.RELEASE; a simple setup not very different from that in  <a href="https://spring.io/guides/gs/rest-service/" rel="noreferrer">Spring REST guide</a>.</p>