错误提示:
当使用 Undertow 作为 Spring Boot 嵌入式服务器时,启动应用。会看到有一条 WARN
日志,如下:
UT026010: Buffer pool was not set on WebSocketDeploymentInfo, the default pool will be used
大致意思是“没有给 WebSocketDeploymentInfo 设置 Buffer pool,将会使用默认值”。
解决方法如下:
1.排除 undertow-websockets-jsr 依赖
如果未使用到 WebSocket 技术,那么可以直接从 spring-boot-starter-undertow
中排除 undertow-websockets-jsr
依赖即可。
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-undertow</artifactId> <exclusions> <!-- 排除 undertow-websockets-jsr 依赖 --> <exclusion> <groupId>io.undertow</groupId> <artifactId>undertow-websockets-jsr</artifactId> </exclusion> </exclusions> </dependency>
2.为 WebSocketDeploymentInfo 设置合理的参数
也可以通过上述的 “编程式” 配置方式,为 WebSocketDeploymentInfo
设置一个合理的参数。如下:
import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory; import org.springframework.boot.web.server.WebServerFactoryCustomizer; import org.springframework.context.annotation.Configuration; import io.undertow.server.DefaultByteBufferPool; import io.undertow.websockets.jsr.WebSocketDeploymentInfo; @Configuration public class UndertowConfiguration implements WebServerFactoryCustomizer<UndertowServletWebServerFactory>{ @Override public void customize(UndertowServletWebServerFactory factory) { factory.addDeploymentInfoCustomizers(deploymentInfo -> { WebSocketDeploymentInfo webSocketDeploymentInfo = new WebSocketDeploymentInfo(); // 设置合理的参数 webSocketDeploymentInfo.setBuffers(new DefaultByteBufferPool(true, 8192)); deploymentInfo.addServletContextAttribute("io.undertow.websockets.jsr.WebSocketDeploymentInfo", webSocketDeploymentInfo); }); } }
经过测试,上述 2 种方式都可以解决 Undertow 启动时有警告日志的问题。
标签:undertow,boot,WebSocketDeploymentInfo,jsr,import,Undertow,日志,警告,websockets From: https://www.cnblogs.com/liuhao-blog/p/18213535