醒醒 ,SpringBoot 中 是时候尝试Undertow 了

springboot 中还在使用Tomat ? 是时候了解下 Undertow 了。

官网: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中使用

项目中排除 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 的依赖

<!--替换内置默认容器-->
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-undertow</artifactId>
</dependency>

启动项目,可以看到启动日志:

Undertow started on port(s) 8080 (http) with context path ''

访问健康检查接口,服务正常在线

3、为什么要使用该容器呢?
  1. 轻量级:一共引入三个Jar 不足5M
  2. WebSocket 支持 :对 Web Socket 完全支持,用以满足 Web 应用巨大数量的客户端
  3. 嵌套性:它不需要容器,只需通过 API 即可快速搭建 Web 服务器

友情提示:

当然如果在生产中使用,一定要经过实际的压测对比,用数据说话。
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容