一、Tomcat配置
1. 通过application.yml配置
以下展示常用配置
server:port: 8182 # 配置端口tomcat:threads:max: 10 # 最大工作线程,默认是200min-spare: 5 # 最小工作线程,默认是10accept-count: 200 # tomcat启动线程达到最大值后,接受的排队请求个数,默认是100max-connections: 2000 # 最大连接数(并发数),默认是8192connection-timeout: 10000 # 建立连接的超时时间,单位是毫秒
2. 通过类配置
@Component
public class CostumizationBean implements WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> {@Overridepublic void customize(ConfigurableServletWebServerFactory servlet) {servlet.setPort(10000); // 设置端口为10000// 还可以进行多种配置}
}
注意:使用配置文件可配置的更全
二、Tomcat切换Undertow
将Tomcat切换为Undertow,主要有以下几个步骤:
- 修改pom.xml,删除Tomcat
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId><!--删除 tomcat --><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>