Spring Boot 1.3 (Spring 4.2) supports
CompletableFuture<T>
andCompletionStage<T>
as aController
return type out of the box. There is no need to add a customMethodReturnValueHandler
.
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: