fix 修复 undertow 新版本无法上传大文件问题

This commit is contained in:
疯狂的狮子Li
2026-02-26 13:43:20 +08:00
parent 24b3fc686f
commit 87fe115677
3 changed files with 13 additions and 2 deletions

View File

@@ -17,7 +17,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>17</java.version>
<spring-boot.version>3.5.9</spring-boot.version>
<spring-boot.version>3.5.11</spring-boot.version>
<spring-cloud.version>2025.0.1</spring-cloud.version>
<spring-boot-admin.version>3.5.6</spring-boot-admin.version>
<mybatis.version>3.5.19</mybatis.version>

View File

@@ -1,11 +1,14 @@
package org.dromara.common.web.config;
import io.undertow.UndertowOptions;
import io.undertow.server.DefaultByteBufferPool;
import io.undertow.server.handlers.DisallowedMethodsHandler;
import io.undertow.util.HttpString;
import io.undertow.websockets.jsr.WebSocketDeploymentInfo;
import org.dromara.common.core.utils.SpringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.core.task.VirtualThreadTaskExecutor;
@@ -18,6 +21,9 @@ import org.springframework.core.task.VirtualThreadTaskExecutor;
@AutoConfiguration
public class UndertowConfig implements WebServerFactoryCustomizer<UndertowServletWebServerFactory> {
@Autowired
private ServerProperties serverProperties;
/**
* 自定义 Undertow 配置
* <p>
@@ -31,6 +37,11 @@ public class UndertowConfig implements WebServerFactoryCustomizer<UndertowServle
*/
@Override
public void customize(UndertowServletWebServerFactory factory) {
long bytes = serverProperties.getUndertow().getMaxHttpPostSize().toBytes();
factory.addBuilderCustomizers(builder -> {
builder.setServerOption(UndertowOptions.MULTIPART_MAX_ENTITY_SIZE, bytes);
});
// 默认不直接分配内存 如果项目中使用了 websocket 建议直接分配
factory.addDeploymentInfoCustomizers(deploymentInfo -> {
// 配置 WebSocket 部署信息,设置 WebSocket 使用的缓冲区池

View File

@@ -2,7 +2,7 @@ server:
# undertow 配置
undertow:
# HTTP post内容的最大大小。当值为-1时默认值为大小是无限的
max-http-post-size: -1
max-http-post-size: 1GB
# 以下的配置会影响buffer,这些buffer会用于服务器连接的IO操作,有点类似netty的池化内存管理
# 每块buffer的空间大小,越小的空间被利用越充分
buffer-size: 512