# 75.1 使用另外的网络服务器

许多Spring Boot程序都包含默认的嵌入式容器。`spring-boot-starter-web`通过包含`spring-boot-starter-tomcat`来包含Tomcat。但是，你可以使用`spring-boot-starter-jetty`或`spring-boot-starter-undertow`来代替。`spring-boot-starter-webflux`通过包含`spring-boot-starter-reactor-netty`，包含了Reactor Netty。但是，你可以使用`spring-boot-starter-tomcat`、`spring-boot-starter-jetty`或者`spring-boot-starter-undertow`来代替。

**注** 许多starter只支持Spring MVC，因此它们将`spring-boot-starter-web`引入到你的应用程序类路径中。

如果需要使用不同的HTTP服务器，则需要排除默认依赖项，并包含所需的依赖项。Spring Boot为HTTP服务器提供了独立的启动程序，以帮助尽可能简化这个过程。

下面的Maven示例展示了如何在Spring MVC中排除Tomcat并包含Jetty：

```markup
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <exclusions>
        <!-- Exclude the Tomcat dependency -->
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<!-- Use Jetty instead -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
```

下面的Gradle例子展示了如何在Spring WebFlux中排除Netty并包含Undertow：

```
configurations {
    // exclude Reactor Netty
    compile.exclude module: 'spring-boot-starter-reactor-netty'
}

dependencies {
    compile 'org.springframework.boot:spring-boot-starter-webflux'
    // Use Undertow instead
    compile 'org.springframework.boot:spring-boot-starter-undertow'
    // ...
}
```

**注** `spring-boot-starter-reactor-netty`需要使用`WebClient`类，所以即使需要包含不同的HTTP服务器，也可能需要保持对Netty的依赖。
