. Advertisement .
..3..
. Advertisement .
..4..
In many places, you can find Java from e-commerce websites to Android applications, from scientific applications to financial applications such as electronic trading systems.
When you try to complete your task, you get this error: “org.springframework.core.io.buffer.DataBufferLimitException: Exceeded limit on max bytes to buffer in Java“.
This error is one of the most popular errors any programmer will make. So, why does it appear, and how can it be resolved? We’ll go over it with you.
Why Does The Error: org.springframework.core.io.buffer.DataBufferLimitException: Exceeded limit on max bytes to buffer in Java Occur?
You face the following error When you are receiving or sending a file, or this warning comes with the new update of Node.js 17. Other user think becasue of adding a new spring.codec.max-in-memory-size
configuration property in Spring Boot.
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
Two Effective Methods For You
And, guess what, we just solved it using some methods listed below.
Method 1: Add spring.codec.max-in-memory-size in config file
Spring Boot only requires you to specify the maximum memory size in the configuration property.
spring:
codec:
max-in-memory-size: 10MB
Your error must now be fixed.
Method 2: Create Bean in the main Springbootapplication class
First and foremost, you need to add a Bean to the main Springbootapplication class. As shown below.
@Bean
public WebClient getWebClientBuilder(){
return WebClient.builder().exchangeStrategies(ExchangeStrategies.builder()
.codecs(configurer -> configurer
.defaultCodecs()
.maxInMemorySize(16 * 1024 * 1024))
.build())
.build();
}
Now, you have to use the WebClient class. Just like this.
WebClient webClient;
public void test(){
String out = webClient
.get()
.uri("end point of an API")
.retrieve()
.bodyToMono(String.class)
.block();
sysout(out)
Method 3: application.yml
file
Adding this command to resolve the problem. Now, we believe that your error has been corrected.
spring:
codec:
max-in-memory-size: 10MB
Conclusion
The solutions mentioned above are the best options for those still confused with this error: “org.springframework.core.io.buffer.DataBufferLimitException: Exceeded limit on max bytes to buffer in Java”.
If you need our support or have other questions, we have a thriving community where everyone is always willing to help. If you want to learn Java, bookmark our Java category and begin learning about this well-known programming language.
We wish you a more productive day filled with new solutions and code.
Leave a comment