Update 64.11. Use Undertow instead of Tomcat.md

master
qibaoguang 2015-03-25 22:33:57 +08:00
parent d40335d9c0
commit 4de9a2415d
1 changed files with 31 additions and 4 deletions

View File

@ -1,7 +1,34 @@
### 64.11. 改变HTTP端口
### 64.11. 使用Undertow替代Tomcat
在一个单独的应用中主HTTP端口默认为8080但可以使用`server.port`设置比如在application.properties中或作为一个系统属性。由于`Environment`值的宽松绑定,你也可以使用`SERVER_PORT`比如作为一个OS环境变
使用Undertow替代Tomcat和[使用Jetty替代Tomcat](https://github.com/qibaoguang/Spring-Boot-Reference-Guide/edit/master/How-to_%20guides.md)非常类似。你需要排除Tomat依赖并包含Undertow starter
为了完全关闭HTTP端点但仍创建一个WebApplicationContext你可以设置`server.port=-1`(测试时可能有用)。
Maven示例
```xml
<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>
```
Gradle示例
```gradle
configurations {
compile.exclude module: "spring-boot-starter-tomcat"
}
想获取更多详情可查看'Spring Boot特性'章节的[Section 26.3.3, “Customizing embedded servlet containers”](http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-customizing-embedded-containers),或[ServerProperties](http://github.com/spring-projects/spring-boot/tree/master/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java)源码。
dependencies {
compile 'org.springframework.boot:spring-boot-starter-web:1.3.0.BUILD-SNAPSHOT")
compile 'org.springframework.boot:spring-boot-starter-undertow:1.3.0.BUILD-SNAPSHOT")
// ...
}
```