Solve the Error “org.springframework.core.io.buffer. DataBufferLimitException: Exceeded limit on max bytes to buffer in Java”

Java is ideal for creating various applications such as games, web, desktop, and mobile. Many other applications can also be created, and that’s the reason programmers are using it all over the world. It is known as a high-level programming language that is easy to work with. Programmers can easily write, compile code, and debug. It is an object-oriented language that allows developers and programmers to design modular programs. Moreover, it has reusable codes, which is obviously an added advantage. When working with Java, you may also face errors, and “org.springframework.core.io.buffer.DataBufferLimitException: Exceeded limit on max bytes to buffer in Java” is one of those.

Though this error seems complex, it is not as tough as it looks. In fact, it can be solved simply. Go ahead with the post to get the issue fixed. Let’s check out how the errors pop up

How do you get the error warning?

When you try to send and receive a file, you end up with the error warning. This is how the error looks like

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)

    Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException

Solutions to Fix the Error “org.springframework.core.io.buffer.DataBufferLimitException: Exceeded limit on max bytes to buffer in Java”

We have three outstanding solutions that can solve all the issues you may face regarding this error. you can try any of the following

Solution 1 – Create Bean in the main class of Springbootapplication.

This is an effective way to fix the error simply. You just need to create Bean in the main class of Springbootapplication. Have a look at the following code

@Bean

public WebClient getWebClientBuilder(){

    return   WebClient.builder().exchangeStrategies(ExchangeStrategies.builder()

            .codecs(configurer -> configurer

                      .defaultCodecs()

                      .maxInMemorySize(16 * 1024 * 1024))

                    .build())

                  .build();

}

Once done, you need to implement the WebClient class. To do that, follow the below code

WebClient webClient;

        public void test(){

         String out = webClient

                      .get()

                      .uri("end point of an API")

                      .retrieve()

                      .bodyToMono(String.class)

                     .block();

         sysout(out)

It helps you resolve the error.

Solution 2 – Add spring.codec.max-in-memory-size in config file

To get rid of the error warning, you should use the configuration property to specify memory size in maximum in the Spring Boot. It is a simpler solution as you just need to type the following

spring:

  codec:

    max-in-memory-size: 10MB

Solution 3 – Set the Max bytes

Another solution to resolve the error is to set the maximum bytes in the Spring Boot configuration file ‘application.properties’. you need to set the bytes in megabytes. Follow this:

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

Conclusion

And that’s how you can simply fix the error “org.springframework.core.io.buffer.DataBufferLimitException: Exceeded limit on max bytes to buffer in Java”. It is on you to choose the solution that suits your project’s needs. All the solutions highlighted in the post are effective as well as simple to execute.

I hope you find it helpful.

Feel free to write to us in the comment box below if you need any assistance. We would love to help you solve the query.

Leave a Reply

Your email address will not be published. Required fields are marked *