webflux单声道响应为空

问题描述 投票:1回答:1

我的项目中有一个非常简单的spring webflux rest端点。

@Bean
public RouterFunction authRoute() {
    return RouterFunctions.route(POST("/auth/signin").and(accept(APPLICATION_JSON)), this::signIn)
            .andRoute(POST("/auth/signup").and(accept(APPLICATION_JSON)), this::signUp)
            .andRoute(POST("/auth/test").and(accept(APPLICATION_JSON)), this::test);
}

[/auth/test端点只需使用提供的用户名回复。

public Mono<ServerResponse> test(ServerRequest request) {
    System.out.println("Start test ");
    Mono<JwtRequest> jwtRequestMono = request.bodyToMono(JwtRequest.class);
    jwtRequestMono.subscribe(v -> System.out.println(v.getUsername() + ":" + v.getPassword()));
    return jwtRequestMono
            .flatMap(j -> ServerResponse.ok().contentType(APPLICATION_JSON).bodyValue(j.getUsername()));
}

terminal

我面临的问题是响应正文为空,应为用户名。我还验证了当我返回硬编码的字符串时,它可以通过。当我依赖jwtRequestMono.flatMap(...时失败

![postman

我在我的项目中有一个非常简单的spring webflux rest端点。 @Bean public RouterFunction authRoute(){返回RouterFunctions.route(POST(“ / auth / signin”)。and(accept(APPLICATION_JSON)),这:: ...

spring-boot mono reactive-programming spring-webflux
1个回答
3
投票

这行几乎可以肯定是您的败笔:

© www.soinside.com 2019 - 2024. All rights reserved.