Spring boot切换Servlet容器

本文介绍如何在SpringBoot中切换默认的Tomcat为Jetty或Undertow作为Servlet容器。通过修改Pom文件,排除Tomcat依赖并引入Jetty或Undertow的启动器,实现Servlet容器的灵活切换。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

切换Servlet容器

Spring boot默认配置Tomcat作为Servlet容器
引入web模块,默认使用嵌入式的Tomcat
可以切换Jetty、Undertow

默认配置
Pom文件,查看依赖关系

默认使用Tomcat
因为,Web引入了Tomcat的启动器

切换Jetty

Pom文件,排除Tomcat启动器依赖
在依赖关系,右键可以排除依赖

<!-- 引入web模块 -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <exclusions>
        <exclusion>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <groupId>org.springframework.boot</groupId>
        </exclusion>
    </exclusions>
</dependency>

引入Jetty启动器

<!--引入其他的Servlet容器-->
<dependency>
    <artifactId>spring-boot-starter-jetty</artifactId>
    <groupId>org.springframework.boot</groupId>
</dependency>

切换undertow

引入undertow启动器

<!--引入其他的Servlet容器-->
<dependency>
    <artifactId>spring-boot-starter-undertow</artifactId>
    <groupId>org.springframework.boot</groupId>
</dependency>
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值