MSIPO技术圈 首页 IT技术 查看内容

Springboot中Tomcat配置及切换Undertow

2024-03-25

一、Tomcat配置

1. 通过application.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. 通过类配置
@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
<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
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>

相关阅读

热门文章

    手机版|MSIPO技术圈 皖ICP备19022944号-2

    Copyright © 2024, msipo.com

    返回顶部