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>
相关推荐
ai小鬼头2 小时前
百度秒搭发布:无代码编程如何让普通人轻松打造AI应用?
前端·后端·github
考虑考虑2 小时前
@FilterRegistration和@ServletRegistration注解
spring boot·后端·spring
一只叫煤球的猫2 小时前
🔥 同事混用@Transactional和TransactionTemplate被我怼了,三种事务管理到底怎么选?
java·spring boot·后端
你的人类朋友9 天前
(●'◡'●)从Dockerfile快速入门Docker Compose
后端
GetcharZp9 天前
「神器推荐」Rclone:轻松玩转云端存储,FTP 也能飞起来!
后端
华子w9089258599 天前
基于 SpringBoot+JSP 的医疗预约与诊断系统设计与实现
java·spring boot·后端
舒一笑9 天前
工作流会使用到Webhook是什么
后端·程序员
止观止9 天前
Rust智能指针演进:从堆分配到零复制的内存管理艺术
开发语言·后端·rust
学無芷境9 天前
Cargo 与 Rust 项目
开发语言·后端·rust
ai小鬼头9 天前
AIStarter开发者熊哥分享|低成本部署AI项目的实战经验
后端·算法·架构