首页 > 解决方案 > 无法在 flatMap 中构建 ResponseEntity

问题描述

我试图在 flatMap 方法中将 ClientResponse 转换为 ResponseEntity 但它返回一个错误。

代码:

Mono<ResponseEntity> response = 
           webClient.post()
                    .uri(requestURI)
                    .exchange()
                    .flatMap(clientResponse -> {

                        ResModel rm = new ResModel();
                        // call setter methods on rm
                        return ResponseEntity.ok(rm);
                    });               

这会引发错误:

不存在类型变量 T 的实例,因此 org.springframework.http.ResponseEntity 符合 reactor.core.publisher.Mono)

我不明白为什么会发生此错误。我也尝试ClientResponse在构建后返回修改但收到类似的错误。

我对 Spring 很陌生,并且已经在这个错误上花了将近 2 天的时间。我也尝试使用flatMapMany这里提到的:https ://stackoverflow.com/a/52332137但得到同样的错误。

谁能告诉我如何解决这个问题以及为什么会发生这种情况

标签: javaspringspring-webfluxspring-rest

解决方案


推荐阅读