SpringBoot2.0实战 | 第六章:SpringBoot配置Undertow服务器

undertow 是一个服务器,在相同资源使用量的情况下 undertow 比 tomcat 有更好的吞吐量和较低的访问时延

本章目标

替换 SpringBoot 的启动服务器 Tomcat 服务器为 Undertow 服务器

操作步骤

添加依赖

引入 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>

验证结果

启动项目,查看启动日志,可以看到如下两行

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

总结

Undertow 是一个比 Tomcat 性能更好的服务器,这是一个优化项。

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容