我的项目中有一个非常简单的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()));
}
我面临的问题是响应正文为空,应为用户名。我还验证了当我返回硬编码的字符串时,它可以通过。当我依赖jwtRequestMono.flatMap(...
时失败
我在我的项目中有一个非常简单的spring webflux rest端点。 @Bean public RouterFunction authRoute(){返回RouterFunctions.route(POST(“ / auth / signin”)。and(accept(APPLICATION_JSON)),这:: ...
这行几乎可以肯定是您的败笔: