org.apache.tomcat.util.modeler.Registry.disableRegistry 方法不存在

今天為了修復(fù)jackson漏洞 要升級(jí)spring 版本,可是升級(jí)了之后報(bào)錯(cuò)

An attempt was made to call a method that does not exist. The attempt was made from the following location:

org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:177)

The following method did not exist:

org.apache.tomcat.util.modeler.Registry.disableRegistry()V

The method's class, org.apache.tomcat.util.modeler.Registry, is available from the following locations:

jar:file:/C:/Users/%e7%8e%8b%e8%b6%85%e5%87%a1/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/8.5.63/tomcat-embed-core-8.5.63.jar!/org/apache/tomcat/util/modeler/Registry.class

The class hierarchy was loaded from the following locations:

org.apache.tomcat.util.modeler.Registry: file:/C:/Users/%e7%8e%8b%e8%b6%85%e5%87%a1/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/8.5.63/tomcat-embed-core-8.5.63.jar

進(jìn)入 TomcatServletWebServerFactory.java:177 查看
@Override
public WebServer getWebServer(ServletContextInitializer... initializers) {
if (this.disableMBeanRegistry) {
Registry.disableRegistry();
}
disableRegistry是紅的說(shuō)明沒(méi)這個(gè)方法

顯示的jar包是 org.springframework.boot:spring-boot:2.3.5.RELEASE

那tomcat 的版本應(yīng)該是spring boot parent里指定的啊 ,為什么

spring boot 內(nèi)嵌的tomcat 版本查看

http://t.zoukankan.com/EasonWu-p-10788757.html

我直接在 pom.xml里 用maven helper dependency Analyzer 查看tomcat版本

image.png

f12點(diǎn)進(jìn)去 查看 spring-boot-starter-web-20.3.5.RELEASE.pom文件

</dependency>
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-tomcat</artifactId>
  <version>2.3.5.RELEASE</version>
  <scope>compile</scope>
</dependency>

而tomcat 2.3.5 的版本

<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<version>9.0.39</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<artifactId>tomcat-annotations-api</artifactId>
<groupId>org.apache.tomcat</groupId>
</exclusion>
</exclusions>

是9.0.39版本啊

根據(jù)錯(cuò)誤日志
The method's class, org.apache.tomcat.util.modeler.Registry, is available from the following locations:

jar:file:/C:/Users/%e7%8e%8b%e8%b6%85%e5%87%a1/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/8.5.63/tomcat-embed-core-8.5.63.jar!/org/apache/tomcat/util/modeler/Registry.class

The class hierarchy was loaded from the following locations:

org.apache.tomcat.util.modeler.Registry: file:/C:/Users/%e7%8e%8b%e8%b6%85%e5%87%a1/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/8.5.63/tomcat-embed-core-8.5.63.jar

進(jìn)入目錄查看C:\Users\王超凡.m2\repository\org\apache\tomcat\embed\tomcat-embed-core\9.0.39
是有9.0.39版本的

也就是說(shuō)這個(gè)maven 錯(cuò)亂了?

在工程里強(qiáng)制指定tomcat 版本

<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<version>9.0.39</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<artifactId>tomcat-annotations-api</artifactId>
<groupId>org.apache.tomcat</groupId>
</exclusion>
</exclusions>
</dependency>

終于能啟動(dòng)正常了

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容