小编Ash*_*Ash的帖子

如何将 Web 客户端响应转换为 ResponseEntity?

我可以使用exchange()现已弃用的方法将 WebClient 响应转换为响应实体。

请建议达到相同结果的其他方法。下面是我的代码。

public ResponseEntity<TestClass> getTestDetails() {
            ClientResponse clientResponse = webClientBuilder.build()
                    .get()
                    .uri("http://localhost:9090/test")
                    .headers(httpHeaders -> {
                        httpHeaders.add(Constants.ACCEPT, Constants.APPLICATION_JSON);
                        })
                    .exchange()
                    .block();
            
            return clientResponse.toEntity(TestClass.class).block();
}
Run Code Online (Sandbox Code Playgroud)

spring reactive-programming spring-boot spring-webflux

0
推荐指数
1
解决办法
5123
查看次数