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>
相关推荐
知兀13 小时前
【Spring/SpringBoot】SSM(Spring+Spring MVC+Mybatis)方案、各部分职责、与Springboot关系
java·spring boot·spring
汤姆yu14 小时前
基于springboot的民间救援队救助系统
java·spring boot·后端·救援队
IT_陈寒14 小时前
React性能优化实战:这5个Hooks技巧让我的应用快了40%
前端·人工智能·后端
ruleslol15 小时前
SpringBoot面试题04-BeanDefinition
spring boot
韩立学长15 小时前
基于Springboot的智慧管网灌溉系统i1agupa7(程序、源码、数据库、调试部署方案及开发环境)系统界面展示及获取方式置于文档末尾,可供参考。
数据库·spring boot·后端
一 乐15 小时前
高校教务|教务管理|基于springboot+vue的高校教务管理系统(源码+数据库+文档)
java·数据库·vue.js·spring boot·后端·教务管理
August_._15 小时前
【MySQL】触发器、日志、锁机制 深度解析
java·大数据·数据库·人工智能·后端·mysql·青少年编程
BingoGo15 小时前
15 个 Eloquent 高级技巧,瞬间提升你的 Laravel 应用性能
后端·php
golang学习记15 小时前
用 Go + Redis + HTMX 手撸一个超快 URL 短链接服务 🚀
后端
codervibe15 小时前
Spring Boot 热启动配置实战:从手动重启到秒级反馈
spring boot·后端