我们知道,SpringBoot 默认使用的嵌入式容器为 Tomcat,SpringBoot 默认还支持将其切换为 Jetty(对长连接有更好的支持) 或 Undertow(不支持 JSP)。
其实通过容器接口的实现类我们就可以看到其它两个容器工厂的实现:
切换为 Jetty
首先我们要排除默认依赖的 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 的场景启动器即可:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
切换为 Undertow
同 Jetty 先排除 Tomcat 的场景启动器,接着引入 Undertow 的场景启动器:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>
评论区