![](/img/trans.png)
[英]Spring webclient throws “Only one connection receive subscriber allowed” when response does not contain media type header
[英]Why do I get `Only one connection receive subscriber allowed` when the response has an HTTP error status code?
在休息请求中,我使用Spring WebClient向Web服务发送另一个请求,并希望将结果返回给调用者:
return webClient.post()
.uri(url)
.body(...)
.retrieve()
.bodyToMono(String::class.java)
.map { ResponseEntity.ok(it) }
现在webservice返回HTTP错误状态代码我收到以下错误:
java.lang.IllegalStateException: Only one connection receive subscriber allowed.
返回状态200代码时,不会引发错误。
我也尝试检查状态并自己抛出异常,但行为仍然相同:
return webClient.post()
.uri(url)
.body(...)
.retrieve()
.onStatus(HttpStatus::isError) { clientResonse ->
clientResonse.bodyToMono(String::class.java)
.map { RuntimeException(it) }
}
.bodyToMono(String::class.java)
.map { ResponseEntity.ok(it) }
我究竟做错了什么?
代码示例在Kotlin中,但我假设每个Java开发人员都可以读取它:)
这是Spring Framework中的一个已知问题,它已在Spring Framework 5.1.4中修复 - 请参阅SPR-17564 。
不幸的是,我不知道这个问题有任何解决方法,因此升级到Spring Framework 5.1.4 / Spring Boot 2.1.2是迄今为止唯一的解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.