1.前言
SpringBoot支持一下嵌入式Servlet容器:
SpringBoot 2.0.3.RELEASE需要Java 8或9以及Spring Framework 5.0.7.RELEASE或更高版本。为Maven 3.2+和Gradle 4提供了明确的构建支持。
2.使用Tomcat
SpringBoot默认的Servlet容器是Tomcat,无需额外配置,只需要引入spring-boot-starter-web依赖。
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies>
启动Application运行截图如下:
3.使用Jetty
SpringBoot将默认的Tomcat切换为Jetty,步骤如下。
<dependencies> <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> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jetty</artifactId> </dependency> </dependencies>
启动Application运行截图如下:
3.1.为什么要使用Jetty
Google App Engine放弃了Tomcat而选择Jetty。主要是因为Jetty相比Tomcat更小更灵活,在云中服务器大小非常重要,因为可能在10秒内运行几千个Jetty实例,如果每个服务器能省下1M,那么10秒内就会省下GB量级的内存。
4.使用Undertow
SpringBoot将默认的Tomcat切换为Undertow,步骤如下。
<dependencies> <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> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-undertow</artifactId> </dependency> </dependencies>
启动Application运行截图如下:
© 著作权归作者所有
发表评论