前几天帮同事解决了一个小问题,感觉挺有必要,小记一下。背景是当前现网运行的SpringBoot项目版本为2.1.6,2.1.6内置Tomcat版本为9.0.21,而此版本的tomcat被局方扫描出了漏洞,需要紧急升级Tomcat到9.0.30。首先想到的办法就是直接升级SpringBoot版本到2.2.3,而项目中依赖的自有框架包使用的是2.1.6版本的包,尝试直接升级,报缺少了部分方法。因此就通过直接修改Tomcat版本方式。
前提
要想知道2.1.6版本的SpringBoot包依赖了什么版本的tomcat,必须找到父工程的依赖。也就是我们在pom文件中经常看到的parent节点
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<relativePath/>
</parent>
spring-boot-dependencies
点进spring-boot-starter-parent可以看到,这个工程还有一个父工程spring-boot-dependencies。这里面定义了所有依赖的jar包与版本
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.1.6.RELEASE</version>
<relativePath>../../spring-boot-dependencies</relativePath>
</parent>
找到该工程的pom,搜索tomcat
<tomcat.version>9.0.21</tomcat.version>
可见该版本确实依赖了9.0.21的tomcat。现直接改成我们目的版本后,重新引入。
<tomcat.version>9.0.30</tomcat.version>
到这就完成了Tomcat版本的配置。
ps:有风险,需确认升级到新版后是否对下兼容




