springboot 中還在使用Tomat ? 是時(shí)候了解下 Undertow 了。
官網(wǎng):http://undertow.io/index.html
1脏嚷、什么是Undertow
Undertow is sponsored by JBoss and is the default web server in the Wildfly Application Server.
Undertow is a flexible performant web server written in java, providing both blocking and non-blocking API’s based on NIO.
2婴噩、如何在spring Boot中使用
項(xiàng)目中排除 Tomcat 依賴
<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>
增加Undertow 的依賴
<!--替換內(nèi)置默認(rèn)容器--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-undertow</artifactId> </dependency>
啟動(dòng)項(xiàng)目擎场,可以看到啟動(dòng)日志:
Undertow started on port(s) 8080 (http) with context path ''
訪問(wèn)健康檢查接口,服務(wù)正常在線
3几莽、為什么要使用該容器呢迅办?
- 輕量級(jí):一共引入三個(gè)Jar 不足5M
- WebSocket 支持 :對(duì) Web Socket 完全支持,用以滿足 Web 應(yīng)用巨大數(shù)量的客戶端
- 嵌套性:它不需要容器章蚣,只需通過(guò) API 即可快速搭建 Web 服務(wù)器