https://docs.spring.io/spring-framework/docs/current/reference/html/web-reactive.html#webflux-ann-responseentity
WebFlux supports using a single value reactive type to produce the
ResponseEntity asynchronously, and/or single and multi-value reactive
types for the body.
So the return type on an annotated controller would actually be a Reactive Publisher like Flux or Mono that emits an object representing the data to return.
Example
Flux<AccountDto>
Or also:
Flux<ResponseEntity<AccountDto>>
I think you can even just set a raw DTO type as the return type and Webflux will automagically wrap it in a publisher for you.
Valid Return Types
https://docs.spring.io/spring-framework/docs/current/reference/html/web-reactive.html#webflux-ann-return-types
Example: https://github.com/oktadeveloper/okta-spring-webflux-react-example/blob/react-app/reactive-web/src/main/java/com/example/demo/ProfileRestController.java
Non-blocking Reactive Paradigm
When doing Reactive Programming you want to every layer to communicate via Flux/Mono. So you would get back a Flux from your ReactiveRepository and the service layer would also return a Flux to the Controller. Basically, in reactive programming everything is a Flux/Mono.
Internals
While SpringMVC and Spring Webflux annotated controllers look similar, they are vastly different internally. For instance, Webflux uses Jetty while SpringMVC uses Tomcat by default. Internally, Webflux is more like a non-blocking event-loop architecture while SpringMVC traditionally leverages a threadpool with 1 thread per request blocking for I/O.
Check out this article for more details on Spring WebFlux
ResponseEntity
. The flux sample returns aResponseEntity
that writes aFlux
, the other returns aFlux
orResponseEntity
instances. – Sinusoid