org.springframework.core.io.buffer.DataBufferLimitException: Exceeded limit on max bytes to buffer :

博客讲述了在 Gateway 自定义过滤器重写请求 ServerRequest 后,架构升级导致请求参数大小限制改变,旧版本默认无限制,新版限制为 256KB。还给出了解决方案,包括添加配置 Bean(失败)和手动设置配置类(成功)。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

org.springframework.core.io.buffer.DataBufferLimitException: Exceeded limit on max bytes to buffer : 262144的问题

由于在 Gateway 的自定义过滤器中重写了请求 ServerRequest,后面因为升级了架构,原本旧版本未对请求参数的大小进行限制(默认取-1),后面升级了新版修改为 256KB 的限制。

解决方案如下:
方案一跟二对于我当然版本的 SpringBoot 不生效,大家可以都尝试一下,有可能可以。
 

spring:
  codec:
    max-in-memory-size: 50MB

二、添加配置 Bean(失败)

@Configuration
@EnableWebFlux
public class WebFluxWebConfig implements WebFluxConfigurer
{
	@Override
	public void configureHttpMessageCodecs(ServerCodecConfigurer configurer) {
		configurer.defaultCodecs().maxInMemorySize(50 * 1024 * 1024);
	}
}

三 手动设置配置类  成功

查询下代码中有没有使用默认reader的地方

HandlerStrategies.withDefaults().messageReaders()

修改如下:

@Autowired
    private ServerCodecConfigurer codecConfigurer;

ServerRequest serverRequest = ServerRequest.create(exchange, codecConfigurer.getReaders());

Gateway 报错org.springframework.core.io.buffer.DataBufferLimitException: Exceeded limit on max bytes.._Thai_的博客-优快云博客

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值