美文网首页开源框架-SpringBoot系列微服务SpringBoot
醒醒 ,SpringBoot 中 是时候尝试Undertow 了

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

作者: 逗逼程序员 | 来源:发表于2020-02-09 15:57 被阅读0次

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 服务器

友情提示:

当然如果在生产中使用,一定要经过实际的压测对比,用数据说话。

相关文章

网友评论

    本文标题:醒醒 ,SpringBoot 中 是时候尝试Undertow 了

    本文链接:https://www.haomeiwen.com/subject/zgfnxhtx.html