70.11 使用Jetty替代Tomcat

Spring Boot starters(特别是spring-boot-starter-web)默认都使用Tomcat作为内嵌容器。想使用Jetty替代Tomcat,你需要排除那些Tomcat的依赖并包含Jetty的依赖。为了简化这种事情的处理,Spring Boot将Tomcat和Jetty的依赖捆绑在一起,然后提供了单独的starters。

Maven示例:

  1. <dependency>
  2. <groupId>org.springframework.boot</groupId>
  3. <artifactId>spring-boot-starter-web</artifactId>
  4. <exclusions>
  5. <exclusion>
  6. <groupId>org.springframework.boot</groupId>
  7. <artifactId>spring-boot-starter-tomcat</artifactId>
  8. </exclusion>
  9. </exclusions>
  10. </dependency>
  11. <dependency>
  12. <groupId>org.springframework.boot</groupId>
  13. <artifactId>spring-boot-starter-jetty</artifactId>
  14. </dependency>

Gradle示例:

  1. configurations {
  2. compile.exclude module: "spring-boot-starter-tomcat"
  3. }
  4. dependencies {
  5. compile("org.springframework.boot:spring-boot-starter-web:1.4.1.RELEASE")
  6. compile("org.springframework.boot:spring-boot-starter-jetty:1.4.1.RELEASE")
  7. // ...
  8. }