|
| 1 | +# 工程简介 |
| 2 | +1. undertow 服务器的官网:[Undertow](https://undertow.io/) |
| 3 | +2. undertow 简介 |
| 4 | + > Undertow 是一个采用 Java 开发的灵活的高性能 Web 服务器,提供包括阻塞和基于 NIO 的非堵塞机制。Undertow 是红帽公司的开源产品,是 Wildfly 默认的 Web 服务器。Undertow 提供一个基础的架构用来构建 Web 服务器,这是一个完全为嵌入式设计的项目,提供易用的构建器 API,完全向下兼容 Java EE Servlet 3.1 和低级非堵塞的处理器。 |
| 5 | +3. Undertow 特点 |
| 6 | + > 1. 高性能 在多款同类产品的压测中,在高并发情况下表现出色。 |
| 7 | + > 2. Servlet4.0 支持 它提供了对 Servlet4.0 的支持。 |
| 8 | + > 3. Web Socket 完全支持,包括JSR-356,用以满足 Web 应用巨大数量的客户端。 |
| 9 | + > 4. 内嵌式 它不需要容器,只需通过 API 即可快速搭建 Web 服务器。 |
| 10 | + > 5. 灵活性 交由链式Handler配置和处理请求,可以最小化按需加载模块,无须加载多余功能。 |
| 11 | + > 6. 轻量级 它是一个 内嵌Web 服务器, 由两个核心 Jar 包组成 |
| 12 | +4. 本项目的目的: |
| 13 | + > 测试使用 undertow 服务器替换 默认的服务器 tomcat |
| 14 | +
|
| 15 | +# 测试流程 |
| 16 | +1. 修改 springboot-web 中的依赖,移除默认的tomcat,核心的maven依赖如下: |
| 17 | + ```xml |
| 18 | + <dependencies> |
| 19 | + |
| 20 | + <dependency> |
| 21 | + <groupId>org.springframework.boot</groupId> |
| 22 | + <artifactId>spring-boot-starter-web</artifactId> |
| 23 | + <exclusions> |
| 24 | + <!-- Exclude the Tomcat dependency --> |
| 25 | + <exclusion> |
| 26 | + <groupId>org.springframework.boot</groupId> |
| 27 | + <artifactId>spring-boot-starter-tomcat</artifactId> |
| 28 | + </exclusion> |
| 29 | + </exclusions> |
| 30 | + </dependency> |
| 31 | + |
| 32 | + <!-- Use Undertow instead --> |
| 33 | + <dependency> |
| 34 | + <groupId>org.springframework.boot</groupId> |
| 35 | + <artifactId>spring-boot-starter-undertow</artifactId> |
| 36 | + </dependency> |
| 37 | + |
| 38 | + </dependencies> |
| 39 | + ``` |
| 40 | +2. 在 `UndertowApplication.java` 中添加测试控制器; |
| 41 | + ```java |
| 42 | + @RestController |
| 43 | + @SpringBootApplication |
| 44 | + public class UndertowApplication { |
| 45 | + public static void main(String[] args) { |
| 46 | + SpringApplication.run(UndertowApplication.class, args); |
| 47 | + } |
| 48 | + |
| 49 | + @GetMapping(path = "/undertow/test") |
| 50 | + public String testUndertowServer() { |
| 51 | + return "use Undertow server success!"; |
| 52 | + } |
| 53 | + } |
| 54 | + ``` |
| 55 | +2. 启动项目`Undertow started on port(s) 8080 (http)` 则说明替换服务器成功。 |
| 56 | +3. 浏览器访问:`http://localhost:8080/` ,返回 `use Undertow server success!` 。 |
| 57 | + |
| 58 | +# Undertow 简单应用 |
| 59 | +1. [Undertow 作为简单的web文件服务器使用](https://www.cnblogs.com/ljgeng/p/11239345.html) |
| 60 | +2. [Spring Boot使用Undertow做服务器](https://blog.csdn.net/sophia63/article/details/104278710) |
| 61 | + |
| 62 | +# 延伸阅读 |
| 63 | +1. [为什么很多 SpringBoot 开发者放弃了 Tomcat,选择了 Undertow?](https://www.rongsoft.com/article/2020/03/052231201487/) |
0 commit comments