최근 Spring의 버전 업데이트를 했는데 갑자기 WebClient에서 아래와 같은 에러가 발생한다.

org.springframework.core.io.buffer.DataBufferLimitException: Exceeded limit on max bytes to buffer : 262144
    at org.springframework.core.io.buffer.LimitedDataBufferList.raiseLimitException(LimitedDataBufferList.java:101) ~[spring-core-5.2.5.RELEASE.jar:5.2.5.RELEASE]
    Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: 

사용중인 Spring 버전

  • Spring boot : 2.2.6.RELEASE
  • Spring framework : 5.2.5.RELEASE

원인

해결

  • 위 이슈를 해결하기 위해서는 WebClient를 build할 때 codec쪽 설정을 넣어줘야 한다.

    ExchangeStrategies exchangeStrategies = ExchangeStrategies.builder()
         .codecs(configurer -> configurer.defaultCodecs().maxInMemorySize(-1)) // to unlimited memory size
         .build();
    
    this.webClient = webClientBuilder
         .exchangeStrategies(exchangeStrategies) // set exchange strategies
         .build();
    • maxInMemorySize를 -1로 줄 경우 unlimited이고 10MB같이 고정하고 싶다면 10 * 1024 * 1024와 같이 넣는다.

참고 자료
https://stackoverflow.com/questions/59326351/configure-spring-codec-max-in-memory-size-when-using-reactiveelasticsearchclient
https://stackoverflow.com/questions/59735951/databufferlimitexception-exceeded-limit-on-max-bytes-to-buffer-webflux-eroor
https://github.com/spring-projects/spring-framework/issues/23961

BELATED ARTICLES

more