Iam从应用程序调用另一个微服务,当数据更多时,Iam得到以下异常
nested exception is org.springframework.web.reactive.function.client.WebClientResponseException: 200 OK from GET https://ops-service.apps.com/api/v1/ops/list?page-size=150&page-offset=0; nested exception is org.springframework.core.io.buffer.DataBufferLimitException: Exceeded limit on max bytes to buffer : 262144] with root cause
org.springframework.core.io.buffer.DataBufferLimitException: Exceeded limit on max bytes to buffer : 262144
at org.springframework.core.io.buffer.LimitedDataBufferList.raiseLimitException(LimitedDataBufferList.java:99) ~[spring-core-5.3.15.jar:5.3.15]
Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException:
Error has been observed at the following site(s):
我试图通过以下方式解决上述异常,但没有成功,仍然得到了异常。在两个微服务的application.properties中都包含了以下行。
spring.codec.max-in-memory-size=70MB
有人能解决上述例外情况吗?
您需要定义一个自定义bean,如下所示:
@Bean("webClient")
public WebClient customWebClient(WebClient.Builder builder) {
return builder.baseUrl(host).build();
}
或者,
@Bean("webClient")
public WebClient customWebClient() {
return WebClient
.builder()
.baseUrl(host)
.exchangeStrategies(ExchangeStrategies
.builder()
.codecs(codecs -> codecs
.defaultCodecs()
.maxInMemorySize(size * 1024 * 1024))
.build())
.build();
}
学分:https://www.baeldung.com/spring-webflux-databufferlimitexception