Search code examples
springspring-restreactor

Spring automatically wrap rest controller response in ResponseEntity


Here is what I'm trying to achieve : I have many spring rest reactive controller returning various Object such as Mono, Flux

I would like to wrap all these response in a ResponseEntity and so always return something like :

Mono<ResponseEntity<MyObjects>>

Any suggestion ?


Solution

  • Just use @ResponseBody Annotation on your controllers

    When you use the @ResponseBody annotation on a method, Spring converts the return value and writes it to the http response automatically. Each method in the Controller class must be annotated with @ResponseBody.

    See the example