java 嵌套的异常是组织.springframework.web.React.函数.客户端.

nhn9ugyo  于 2023-02-07  发布在  Java
关注(0)|答案(1)|浏览(87)

我正在从应用程序调用另一个微服务,当数据较多时,我收到以下异常

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):

我试图通过以下方法解决上述异常,但没有成功,仍然得到异常。在两个micorservices中的www.example.com中包含以下行application.properties。

spring.codec.max-in-memory-size=70MB

对于上述例外情况,有人有解决方案吗?

sdnqo3pr

sdnqo3pr1#

您需要定义一个自定义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

相关问题