Search code examples
springreactor

How to get a Flux from a Mono flatmap?


I have the following code:

public Flux<Foo> getFoos(String xyz) {
    return getBar(xyz).flatMap(b -> Flux.empty()));
}

But it results in a compilation error because getBars() returns a Mono<Bar> instead of a Flux<Bar>. How can I return a Flux from a flatMap() of a Mono value? Thanks.


Solution

  • Found the solution. I just had to use flatMapMany() instead of flatMap()