专业的编程技术博客社区

网站首页 > 博客文章 正文

SpringBoot修改内置web容器(springboot修改默认配置)

baijin 2024-10-29 13:07:28 博客文章 14 ℃ 0 评论

SpringBoot内置了三款web容器,分别是Tomcat、Jetty、undertow,默认的容器是Tomcat,三款web容器各有优点,总体来说差别不大,一般情况下,Tomcat就能满足我们的使用需求。

三款web容器的优点如下:

Tomcat:性能优异,相对来说运行过程中会加载一些比较重的组件,运行效率受一定影响;

Jettty: 轻量级应用,加载组件少,适合小项目,性能不高;



undertow: 性能比Tomcat有优势,使用的人群小;

一、默认Tomcat容器

在Springboot项目的pom配置文件中引入了spring-boot-starter-web中,包含了对Tomcat的引用。



启动Springboot项目后能看到Tomcat容器的启动日志:


二、修改为Jetty容器

首先需要在spring-boot-starter-web中排除对Tomcat的引用。

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
</dependency>

然后引入jetty的starter

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jetty</artifactId>
</dependency>

刷新pom文件,下载相关的jar包,然后启动SpringBoot项目。

这时能看到启动日志中,web容器已经变成了Jetty。


三、修改为undertow容器

首先需要在spring-boot-starter-web中排除对Tomcat的引用。

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
</dependency>

然后引入undertow的starter

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-undertow</artifactId>
</dependency>

刷新pom文件,下载相关的jar包,然后启动SpringBoot项目。

这时能看到启动日志中,web容器已经变成了undertow。


本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表