SpringBoot 改用undertow 替换自带tomcat


个人测试发现undertow 和 tomcat 性能都差不多,但是内存占用会少一点(大概少了10%),尝试换上去测一下,没发现什么毛病,下面记录一下切换使用的要点。

1. 排除tomcat 依赖

            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
                <version>${spring-boot.version}</version>
                <exclusions>
                    <exclusion>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-tomcat</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>

 

2. 使用 jakarta.servlet-api

提示原文如下

the contracts between a servlet class and the runtime environment provided for an instance of such a class by a conforming servlet container. For versions prior to 4.0.2 these classes and interfaces are described by the Java Servlet API Specification. For version 4.0.2 and later they are described by the Jakarta Servlet Specification

我们使用undertow 依赖 jakarta.servlet-api 这个包,在4.0.2 版本之后改用到  jakarta.servlet-api 这个包,好处是包更小了。

            <dependency>
                <groupId>jakarta.servlet</groupId>
                <artifactId>jakarta.servlet-api</artifactId>
                <version>${jakarta-servlet.version}</version>
            </dependency>

在要使用 HttpServletRequest  的时候添加 Jakarta 依赖就可以了。

测试项目使用的springboot 版本为 2.2.2.RELEASE, Jakarta 版本为 4.0.3。

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM