undertow 是一個服務(wù)器镇饮,在相同資源使用量的情況下 undertow 比 tomcat 有更好的吞吐量和較低的訪問時延
本章目標(biāo)
替換 SpringBoot 的啟動服務(wù)器 Tomcat 服務(wù)器為 Undertow 服務(wù)器
操作步驟
添加依賴
引入 Spring Boot Starter 父工程
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.5.RELEASE</version>
</parent>
在引入 spring-boot-starter-web
依賴時,剔除出對 tomcat
的依賴颤枪,然后再添加對 undertow
的依賴用于替換 tomcat
氢卡。
<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>
驗證結(jié)果
啟動項目,查看啟動日志众雷,可以看到如下兩行
Undertow started on port(s) 8080 (http) with context path ''
Started Application in 2.763 seconds (JVM running for 3.658)
源碼地址
本章源碼 : https://gitee.com/gongm_24/spring-boot-tutorial.git
總結(jié)
Undertow 是一個比 Tomcat 性能更好的服務(wù)器讼庇,這是一個優(yōu)化項绎巨。