From fcfd49474731ff112939d648c97a38111352f502 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Mon, 29 May 2023 00:00:08 +0800 Subject: [PATCH] =?UTF-8?q?34=20=E4=BF=AE=E5=A4=8Dbody=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E8=BF=87=E5=A4=A7=E8=B6=85=E8=BF=87=E9=BB=98=E8=AE=A4256K?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E6=8A=A5=E9=94=99(DataBufferLimitException:?= =?UTF-8?q?=20Exceeded=20limit=20on=20max=20bytes=20to=20buffer),=20?= =?UTF-8?q?=E4=BF=AE=E6=94=B9spring.codec.max-in-memory-size=E4=B9=9F?= =?UTF-8?q?=E6=97=A0=E6=95=88=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yudao/gateway/filter/logging/AccessLogFilter.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/yudao-gateway/src/main/java/cn/iocoder/yudao/gateway/filter/logging/AccessLogFilter.java b/yudao-gateway/src/main/java/cn/iocoder/yudao/gateway/filter/logging/AccessLogFilter.java index 984ee4108..ae79bf605 100644 --- a/yudao-gateway/src/main/java/cn/iocoder/yudao/gateway/filter/logging/AccessLogFilter.java +++ b/yudao-gateway/src/main/java/cn/iocoder/yudao/gateway/filter/logging/AccessLogFilter.java @@ -37,6 +37,7 @@ import org.springframework.web.server.ServerWebExchange; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; +import javax.annotation.Resource; import java.nio.charset.StandardCharsets; import java.time.LocalDateTime; import java.util.List; @@ -57,10 +58,7 @@ import static cn.hutool.core.date.DatePattern.NORM_DATETIME_MS_FORMATTER; @Component public class AccessLogFilter implements GlobalFilter, Ordered { - /** - * 解决spring.codec.max-in-memory-size设置不生效的问题 - */ - @Autowired + @Resource private CodecConfigurer codecConfigurer; /** @@ -141,6 +139,7 @@ public class AccessLogFilter implements GlobalFilter, Ordered { */ private Mono filterWithRequestBody(ServerWebExchange exchange, GatewayFilterChain chain, AccessLog gatewayLog) { // 设置 Request Body 读取时,设置到网关日志 + // 此处 codecConfigurer.getReaders() 的目的,是解决 spring.codec.max-in-memory-size 不生效 ServerRequest serverRequest = ServerRequest.create(exchange, codecConfigurer.getReaders()); Mono modifiedBody = serverRequest.bodyToMono(String.class).flatMap(body -> { gatewayLog.setRequestBody(body);