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>
相关推荐
llz_11224 分钟前
web-第二次课后作业
前端·后端·web
红尘散仙6 小时前
我把终端小说阅读器接上了 AI Agent:TRNovel 现在能用 skill 生成书源了
人工智能·后端·rust
来杯@Java7 小时前
图书管理系统(基于springboot+vue前后端分离的项目)计算机毕业设计java
java·spring boot·spring·vue·毕业设计·mybatis·课程设计
卷毛的技术笔记8 小时前
告别硬编码!Spring AI Alibaba 实现 AI Agent 智能工具调用(Tool Calling)
java·人工智能·后端·python·spring·ai编程
会编程的土豆8 小时前
Go 语言反射(Reflection)详解
开发语言·后端·golang
喵个咪8 小时前
GoWind Toolkit Go后端代码生成 完整全流程实战
后端·go·orm
basketball6169 小时前
Go 语言从入门到进阶:4. 数组和MAP使用方法总结
开发语言·后端·golang
qq_2518364579 小时前
SpringBoot+Vue 共享电池柜管理系统 完整实现 前后端分离项目实战 完整代码
vue.js·spring boot·后端
zhangxingchao9 小时前
AI 大模型核心六:量化、Workflow 与 Agent、多轮 RAG
前端·人工智能·后端
IT_陈寒10 小时前
Vite打包时遇到的坑,原来问题出在这里
前端·人工智能·后端