[英]Spring WebClient async callback not called when http server response 404
A problem I encountered is as titled, and the code is below: 我遇到的一个问题如标题所示,代码如下:
Mono<Account> accountMono = client.get()
.uri("accounturl")
.accept(MediaType.APPLICATION_JSON)
.exchange()
.flatMap(response -> {
if (response.statusCode().equals(HttpStatus.OK)) {
return response.bodyToMono(Account.class);
} else {
return Mono.empty();
}
});
accountMono.subscribe(result -> callback(result));
``` ```
Server response 404
. Server response 404
。 I try to create an empty Account, but the callback()
is not called. 我尝试创建一个空帐户,但未
callback()
。 It looks like the empty Mono
is not emitted. 好像没有发出空的
Mono
。
Server response 404, I try to create a empty Account
服务器响应404,我尝试创建一个空帐户
You're not creating an empty Account
. 您不是要创建一个空
Account
。 You're returning an empty Mono
, ie a Mono
that will never emit anything. 您将返回一个空的
Mono
,即一个永远不会发出任何东西的Mono
。
If you want to return a Mono which emits an empty Account, then you need 如果您想返回一个发出空帐户的Mono,则需要
return Mono.just(new Account());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.