【问题标题】:Unable to read values from Flux / Mono无法从 Flux / Mono 读取值
【发布时间】:2018-05-05 03:35:42
【问题描述】:

我有一个简单的程序,它包含两个部分:一个 Spring 5 服务器,它有一个返回 Mono 的端点,以及一个读取值并打印它的客户端程序。

当我浏览到http://localhost:8080/rand 时,会返回一个双精度值。但是,当我使用客户端时,检索到的值始终为 null(响应状态为 200)。

我错过了什么?

文件 Main.java

@SpringBootApplication
@EnableWebFlux
public class Main {
    public static void main(String... args) {
        SpringApplication.run(Main.class);
    }
}

文件 MyController.java

@RestController
public class MyController {
    @GetMapping("/rand")
    public Mono<Double> GetDouble() {
        return Mono.just(ThreadLocalRandom.current().nextDouble());
    }
}

文件 MyClient.java

public class MyClient {
    public static void main(String... args) {
        WebClient client = WebClient.create("http://localhost:8080");

        Double value = client.get()
                .uri("/rand")
                .accept(MediaType.APPLICATION_JSON)
                .retrieve()
                .bodyToMono(Double.class)
                .block();
        System.out.println("value = " + value);
    }
}

【问题讨论】:

标签: spring-boot project-reactor spring-webflux reactor-netty


【解决方案1】:

这是 Spring Framework 5.0.1 的一个已知问题,请参阅 SPR-16166 了解更多信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-04
    • 1970-01-01
    • 1970-01-01
    • 2020-02-28
    • 2019-09-25
    • 2021-09-30
    • 2021-08-14
    • 2021-07-31
    相关资源
    最近更新 更多