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