Springboot中Tomcat配置及切换Undertow

一、Tomcat配置

1. 通过application.yml配置

以下展示常用配置

yml 复制代码
server:
  port: 8182 # 配置端口
  tomcat:
    threads:
      max: 10  # 最大工作线程,默认是200
      min-spare: 5 # 最小工作线程,默认是10
    accept-count: 200 # tomcat启动线程达到最大值后,接受的排队请求个数,默认是100
    max-connections: 2000 # 最大连接数(并发数),默认是8192
    connection-timeout: 10000 # 建立连接的超时时间,单位是毫秒
2. 通过类配置
java 复制代码
@Component
public class CostumizationBean implements WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> {
    @Override
    public void customize(ConfigurableServletWebServerFactory servlet) {

        servlet.setPort(10000); // 设置端口为10000
		// 还可以进行多种配置

    }
}

注意:使用配置文件可配置的更全

二、Tomcat切换Undertow

将Tomcat切换为Undertow,主要有以下几个步骤:

  1. 修改pom.xml,删除Tomcat
xml 复制代码
<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>
  1. 加入undertow
xml 复制代码
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>
相关推荐
卷福同学5 小时前
【养虾日记】Openclaw操作浏览器自动化发文
人工智能·后端·算法
江湖十年6 小时前
Go 并发控制:sync.Pool 详解
后端·面试·go
xdl25996 小时前
Spring Boot中集成MyBatis操作数据库详细教程
数据库·spring boot·mybatis
zb200641206 小时前
Spring Boot 实战:轻松实现文件上传与下载功能
java·数据库·spring boot
jwn9996 小时前
Spring Boot 整合 Keycloak
java·spring boot·后端
mldlds7 小时前
SpringBoot详解
java·spring boot·后端
kang_jin7 小时前
Spring Boot 自动配置
java·spring boot·后端
yuweiade7 小时前
Spring Boot中使用Server-Sent Events (SSE) 实现实时数据推送教程
java·spring boot·后端
小箌7 小时前
springboot_03
spring boot·后端·状态模式
冬奇Lab7 小时前
一天一个开源项目(第54篇):Supabase - 开源的 Postgres 开发平台,Firebase 替代方案
后端·开源·资讯