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>
相关推荐
zs宝来了18 分钟前
Spring Boot Starter 机制:如何编写自定义 Starter
spring boot·starter·最佳实践·自定义启动器
刘~浪地球25 分钟前
Nginx + Tomcat 整合实战(二):反向代理深度配置
nginx·tomcat·firefox
weixin_7042660529 分钟前
Spring 注解驱动开发与 Spring Boot 核心知识点梳理
java·spring boot·spring
无籽西瓜a42 分钟前
【西瓜带你学设计模式 | 第五期 - 建造者模式】建造者模式 —— 产品构建实现、优缺点与适用场景及模式区别
java·后端·设计模式·软件工程·建造者模式
小江的记录本1 小时前
【Spring注解】Spring生态常见注解——面试高频考点总结
java·spring boot·后端·spring·面试·架构·mvc
计算机学姐2 小时前
基于SpringBoot的奶茶店点餐系统【协同过滤推荐算法+数据可视化统计】
java·vue.js·spring boot·mysql·信息可视化·tomcat·推荐算法
程序员cxuan2 小时前
来了来了,Claude Code 全架构解析 !!!
人工智能·后端·claude
艾莉丝努力练剑2 小时前
【Linux信号】Linux进程信号(下):可重入函数、Volatile关键字、SIGCHLD信号
linux·运维·服务器·c++·人工智能·后端·学习
常利兵2 小时前
Spring Boot 实现网络限速:让流量“收放自如”
网络·spring boot·后端
掘金者阿豪2 小时前
Claude Code“泄漏源码”曝光:Anthropic 最强终端 AI,原来早就不是聊天工具了
后端