Boot1.5默认支持三种嵌入式容器:Tomcat(默认)、Jetty、Undertow,Boot2.0新增了Netty
如何更换嵌入式容器了,首先看一下依赖关系,如图:
在spring-boot-starter-web中,依赖了spring-boot-starter-tomcat,我们只需要将该启动依赖去掉,任何加上其他容器启动依赖即可
1. 更换为Jetty容器
1.1 去掉tomcat启动依赖
<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>
1.2 添加Jetty启动依赖
<!-- 添加Jetty容器 -->
<dependency>
<artifactId>spring-boot-starter-jetty</artifactId>
<groupId>org.springframework.boot</groupId>
</dependency>
启动项目,运行结果如图:
证明已经成功的切换成了Jetty
2. 更换为Undertow
方法与Jetty一样