title: Spring Boot REST API - request timeout?
body: <p>I have a Spring Boot REST service that sometimes call third party services as a part of a request. I would like to set a timeout on all my resources (let's say 5 seconds), so that if any request handling (the whole chain, from incoming to response) takes longer than 5 seconds my controllers responds with HTTP 503 instead of the actual response. It would be awesome if this was just a Spring property, for example setting </p>
  
  <pre><code>spring.mvc.async.request-timeout=5000
  </code></pre>
  
  <p>but I haven't had any luck with that. I've also tried extending WebMvcConfigurationSupport and overriding configureAsyncSupport:</p>
  
  <pre><code>@Override
  public void configureAsyncSupport(final AsyncSupportConfigurer configurer) {
      configurer.setDefaultTimeout(5000);
      configurer.registerCallableInterceptors(timeoutInterceptor());
  }
  
  @Bean
  public TimeoutCallableProcessingInterceptor timeoutInterceptor() {
      return new TimeoutCallableProcessingInterceptor();
  }
  </code></pre>
  
  <p>without any luck.</p>
  
  <p>I suspect I have to manually time all my third party calls, and if they take too long, throw a timeout exception. Is that right? Or is there any easier, holistic solution that covers all my request endpoints?</p>