Containers such as Tomcat, Undertow, and jetty are used in the SpringBoot project;
1. Tomcat container is used by default, just run the project directly: Java -jar xxx.jar
server:
tomcat:
uri-encoding: UTF-8
min-spare-threads: 500
max-threads: 2500
max-connections: 6500
accept-count: 1000
max-http-header-size: 1048576
port: 8080
connection-timeout: 12000
servlet:
context-path: /song
2. Use undertow container
2-1 Introduce Maven dependencies and block built-in Tomcat
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>
2-2 Common configuration references for Undertow containers
server.undertow.accesslog.enabled=false
server.undertow.accesslog.dir=logs
server.undertow.threads.io=8
server.undertow.threads.worker=256
server.undertow.max-http-post-size=4MB
server.undertow.buffer-size=1024
server.undertow.direct-buffers=true
2-3 A special error warning and processing method
解决使用undertow容器报io.undertow.websockets.jsr -
UT026010: Buffer pool was not set on WebSocketDeploymentInfo, the default pool will be used
2-3-1 Add a new class with component annotation, as follows:
@Component
public class UndertowPoolCustomizer implements WebServerFactoryCustomizer<UndertowServletWebServerFactory> {
@Override
public void customize(UndertowServletWebServerFactory factory) {
factory.addDeploymentInfoCustomizers(deploymentInfo -> {
WebSocketDeploymentInfo webSocketDeploymentInfo = new WebSocketDeploymentInfo();
webSocketDeploymentInfo.setBuffers(new DefaultByteBufferPool(false, 1024));
deploymentInfo.addServletContextAttribute("io.undertow.websockets.jsr.WebSocketDeploymentInfo", webSocketDeploymentInfo);
});
}
}
2-4 Start, observe the console to verify
3. Use jetty container
3-1 Introduce Maven dependencies and block built-in Tomcat
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
3-2 Common configuration references for jetty containers
server.port=8080
server.servlet.context-path=/home
server.jetty.acceptors=100
server.jetty.max-http-post-size=0
server.jetty.selectors=10
3-3 Start the SpringBoot application and you will find that jetty has started running