一、Tomcat配置
1. 通过application.yml配置
以下展示常用配置
server:
port: 8182
tomcat:
threads:
max: 10
min-spare: 5
accept-count: 200
max-connections: 2000
connection-timeout: 10000
2. 通过类配置
@Component
public class CostumizationBean implements WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> {
@Override
public void customize(ConfigurableServletWebServerFactory servlet) {
servlet.setPort(10000);
}
}
注意:使用配置文件可配置的更全
二、Tomcat切换Undertow
将Tomcat切换为Undertow,主要有以下几个步骤:
- 修改pom.xml,删除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>
- 加入undertow
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>