在用gateway进行审计日志处理时出现报错,原因:gateway请求体过大,或者响应体过大造成缓存不足
springcloud gateway Exceeded limit on max bytes to buffer : 262144
解决办法
响应体过大解决方案,添加配置增加响应缓存大小
@Component
public class LocalBeanConfig {
@Value("${business.maxInMemorySize}")
private int maxInMemorySize;
@Bean
public ExchangeStrategies exchangeStrategies(){
return ExchangeStrategies.builder().codecs(configurer -> configurer.defaultCodecs().maxInMemorySize(maxInMemorySize)).build();
}
}
请求体过大解决方案,添加配置不生效的原因,是因为每次都是重新创建serverRequest,导致配置不生效
添加配置文件
spring.codec.max-in-memory-size=-1
@Autowired
private ServerCodecConfigurer serverCodecConfigurer;
//ServerRequest serverRequest = new DefaultServerRequest(exchange); 每次都重新创建
ServerRequest serverRequest = ServerRequest.create(exchange, serverCodecConfigurer.getReaders());