본문 바로가기

프로그래밍/Spring

[Spring] exceeded limit on max bytes to buffer : 262144

*문제상황 : webclient를 사용하던 중 exceeded limit on max bytes to buffer : 262144 오류가 발생했다. 구체적으로 말하면, webclient를 요청하는 데이터의 크기가 엄청나게 커져서 발생하는 오류였다(Json 데이터가 몇 MB바이트 였음)

*원인 : buffer를 초과해서 익셉션 발생

*해결방법 : webclient을 생성시 exchangeStrategies 옵션을 주어 해결

 

*수정 전 소스

if( webClient == null ) {
    webClient = WebClient.builder()
            .baseUrl("http://localhost:8401")
            .build();
}

 

*수정 후 소스

//[시작] 전송 데이터 용량 제한 없앰
if( strategies == null){
    strategies = ExchangeStrategies
            .builder()
            .codecs(configurer -> {
                configurer
                        .defaultCodecs()
                        .maxInMemorySize(-1);
            }).build();
}
//[종료] 전송 데이터 용량 제한 없앰

if( webClient == null ) {
    webClient = WebClient.builder()
            .baseUrl("http://localhost:8401")
            .exchangeStrategies(strategies)
            .build();
}

 

*참고
[Spring] DataBufferLimitException: Exceeded limit on max bytes to buffer : 262144 에러에 대한 해결 책 (tistory.com)