spring-boot-async-completablefuture


Spring Boot 1.3 (Spring 4.2) supports CompletableFuture<T> and CompletionStage<T> as a Controller return type out of the box. There is no need to add a custom MethodReturnValueHandler.


This sample enables Spring MVC to handle JDK8 CompletableFuture as a result returned by a controller:

  @RequestMapping(value = "/async", method = RequestMethod.GET)
  public CompletableFuture<ModelAndView> indexAsync() {
    CompletableFuture<ModelAndView> futureModelAndView = new CompletableFuture<>();

    ... async processing ...

    return futureModelAndView;
  }

It is always astonishing how extensible Spring is.

References: