mirror of
https://gitee.com/dromara/RuoYi-Cloud-Plus.git
synced 2026-04-27 21:29:37 +08:00
update 不兼容整体升级 springboot 4.X
update springboot 3.5 => 4.0 update springcloud 2025.0 => 2025.1 update springcloud-alibaba 2025.0 => 2025.1 update nacos 2.5 => 3.1 update spring-boot-admin 3.5 => 4.0 update springdoc 2.8 => 3.0 update mybatis-plus 3.5.14 => 3.5.15 update redisson 3.52.0 => 4.3.0 update dynamic-ds 4.3.1 => 4.5.0
This commit is contained in:
@@ -2,7 +2,7 @@ package org.dromara.common.web.config;
|
||||
|
||||
import org.dromara.common.web.core.I18nLocaleResolver;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
|
||||
import org.springframework.boot.webmvc.autoconfigure.WebMvcAutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.web.servlet.LocaleResolver;
|
||||
|
||||
|
||||
@@ -1,75 +1,43 @@
|
||||
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;
|
||||
|
||||
/**
|
||||
* Undertow 自定义配置
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@AutoConfiguration
|
||||
public class UndertowConfig implements WebServerFactoryCustomizer<UndertowServletWebServerFactory> {
|
||||
|
||||
@Autowired
|
||||
private ServerProperties serverProperties;
|
||||
|
||||
/**
|
||||
* 自定义 Undertow 配置
|
||||
* <p>
|
||||
* 主要配置内容包括:
|
||||
* 1. 配置 WebSocket 部署信息
|
||||
* 2. 在虚拟线程模式下使用虚拟线程池
|
||||
* 3. 禁用不安全的 HTTP 方法,如 CONNECT、TRACE、TRACK
|
||||
* </p>
|
||||
*
|
||||
* @param factory Undertow 的 Web 服务器工厂
|
||||
*/
|
||||
@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 使用的缓冲区池
|
||||
WebSocketDeploymentInfo webSocketDeploymentInfo = new WebSocketDeploymentInfo();
|
||||
webSocketDeploymentInfo.setBuffers(new DefaultByteBufferPool(true, 1024));
|
||||
deploymentInfo.addServletContextAttribute("io.undertow.websockets.jsr.WebSocketDeploymentInfo", webSocketDeploymentInfo);
|
||||
|
||||
// 如果启用了虚拟线程,配置 Undertow 使用虚拟线程池
|
||||
if (SpringUtils.isVirtual()) {
|
||||
// 创建虚拟线程池,线程池前缀为 "undertow-"
|
||||
VirtualThreadTaskExecutor executor = new VirtualThreadTaskExecutor("undertow-");
|
||||
// 设置虚拟线程池为执行器和异步执行器
|
||||
deploymentInfo.setExecutor(executor);
|
||||
deploymentInfo.setAsyncExecutor(executor);
|
||||
}
|
||||
|
||||
// 配置禁止某些不安全的 HTTP 方法(如 CONNECT、TRACE、TRACK)
|
||||
deploymentInfo.addInitialHandlerChainWrapper(handler -> {
|
||||
// 禁止三个方法 CONNECT/TRACE/TRACK 也是不安全的 避免爬虫骚扰
|
||||
HttpString[] disallowedHttpMethods = {
|
||||
HttpString.tryFromString("CONNECT"),
|
||||
HttpString.tryFromString("TRACE"),
|
||||
HttpString.tryFromString("TRACK")
|
||||
};
|
||||
// 使用 DisallowedMethodsHandler 拦截并拒绝这些方法的请求
|
||||
return new DisallowedMethodsHandler(handler, disallowedHttpMethods);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
//package org.dromara.common.web.config;
|
||||
//
|
||||
//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.boot.autoconfigure.AutoConfiguration;
|
||||
//import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory;
|
||||
//import org.springframework.boot.web.server.WebServerFactoryCustomizer;
|
||||
//import org.springframework.core.task.VirtualThreadTaskExecutor;
|
||||
//
|
||||
///**
|
||||
// * Boot 4 迁移后默认改用 Jetty,这里暂时保留 Undertow 配置实现以便后续回切时参考。
|
||||
// */
|
||||
//@AutoConfiguration
|
||||
//public class UndertowConfig implements WebServerFactoryCustomizer<UndertowServletWebServerFactory> {
|
||||
//
|
||||
// @Override
|
||||
// public void customize(UndertowServletWebServerFactory factory) {
|
||||
// factory.addDeploymentInfoCustomizers(deploymentInfo -> {
|
||||
// WebSocketDeploymentInfo webSocketDeploymentInfo = new WebSocketDeploymentInfo();
|
||||
// webSocketDeploymentInfo.setBuffers(new DefaultByteBufferPool(true, 1024));
|
||||
// deploymentInfo.addServletContextAttribute("io.undertow.websockets.jsr.WebSocketDeploymentInfo", webSocketDeploymentInfo);
|
||||
//
|
||||
// if (SpringUtils.isVirtual()) {
|
||||
// VirtualThreadTaskExecutor executor = new VirtualThreadTaskExecutor("undertow-");
|
||||
// deploymentInfo.setExecutor(executor);
|
||||
// deploymentInfo.setAsyncExecutor(executor);
|
||||
// }
|
||||
//
|
||||
// deploymentInfo.addInitialHandlerChainWrapper(handler -> {
|
||||
// HttpString[] disallowedHttpMethods = {
|
||||
// HttpString.tryFromString("CONNECT"),
|
||||
// HttpString.tryFromString("TRACE"),
|
||||
// HttpString.tryFromString("TRACK")
|
||||
// };
|
||||
// return new DisallowedMethodsHandler(handler, disallowedHttpMethods);
|
||||
// });
|
||||
// });
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
||||
Reference in New Issue
Block a user