19.1 基本介绍
SpringBoot 支持的 webServer 有如下几个:
server:
#配置端口
port: 9999
tomcat: #对Tomcat进行配置
threads:
max: 10 #最大的工作线程,默认是 200
min-spare: 5 #最小工作线程,默认是 10
accept-count: 200 #Tomcat启动的线程达到最大值(max-connections),接受排队的请求个数,默认是 100
max-connections: 2000 #最大连接数,并发数
connection-timeout: 10000 #建立连接的超时时间,单位是毫秒,这里设置的是 10秒
# 还有很多其他配置...可以查看 SpringBoot 第2章节 配置大全
package com.xjs.springboot.config;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
import org.springframework.stereotype.Component;
/**
* @Author: 谢家升
* @Version: 1.0
*
* 通过类来配置Tomcat
*/
@Component
public class CustomizationBean implements WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> {
@Override
public void customize(ConfigurableServletWebServerFactory server) {
server.setPort(5200); //设置server的端口为 5200
}
}
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-webartifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-tomcatartifactId>
exclusion>
exclusions>
dependency>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-undertowartifactId>
dependency>