十、Spring Boot 切换其他嵌入式Servlet 容器
SpringBoot默认还支持Jetty和Undertow容器,Undertow是一个高性能非阻塞的Servlet容器,并发性能很好,但是不支持JSP。Jetty更适合开发一些长连接Web应用,如Web聊天。
ConfigurableEmbeddedServletContainer继承树:
SpringBoot默认使用的是Tomcat,如果要切换其他容器,则只需要在pom文件中去掉Tomcat依赖,添加其他依赖,如Jetty。
示例:
<!-- 引入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>
<!--引入其他的Servlet容器-->
<dependency>
<artifactId>spring-boot-starter-jetty</artifactId>
<groupId>org.springframework.boot</groupId>
</dependency>