Class CompletableFutureReturnValueHandler

java.lang.Object
org.springframework.messaging.handler.invocation.AbstractAsyncReturnValueHandler
org.springframework.messaging.handler.invocation.CompletableFutureReturnValueHandler
All Implemented Interfaces:
AsyncHandlerMethodReturnValueHandler, HandlerMethodReturnValueHandler

public class CompletableFutureReturnValueHandler extends AbstractAsyncReturnValueHandler
Support for CompletableFuture (and as of 4.3.7 also CompletionStage) as a return value type.
Since:
4.2
Author:
Sebastien Deleuze, Juergen Hoeller
  • Constructor Details

    • CompletableFutureReturnValueHandler

      public CompletableFutureReturnValueHandler()
  • Method Details

    • supportsReturnType

      public boolean supportsReturnType(org.springframework.core.MethodParameter returnType)
      Description copied from interface: HandlerMethodReturnValueHandler
      Whether the given method return type is supported by this handler.
      Parameters:
      returnType - the method return type to check
      Returns:
      true if this handler supports the supplied return type; false otherwise
    • toCompletableFuture

      public CompletableFuture<?> toCompletableFuture(Object returnValue, org.springframework.core.MethodParameter returnType)
      Description copied from interface: AsyncHandlerMethodReturnValueHandler
      Adapt the asynchronous return value to a CompletableFuture.

      Return value handling will then continue when the CompletableFuture is completed with either success or error.

      Note: this method will only be invoked after HandlerMethodReturnValueHandler.supportsReturnType(org.springframework.core.MethodParameter) is called and it returns true.

      Parameters:
      returnValue - the value returned from the handler method
      returnType - the type of the return value
      Returns:
      the resulting CompletableFuture, or null in which case no further handling will be performed