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

今天为了修复jackson漏洞 要升级spring 版本,可是升级了之后报错

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

进入 TomcatServletWebServerFactory.java:177 查看
@Override
public WebServer getWebServer(ServletContextInitializer... initializers) {
if (this.disableMBeanRegistry) {
Registry.disableRegistry();
}
disableRegistry是红的说明没这个方法

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

那tomcat 的版本应该是spring boot parent里指定的啊 ,为什么

spring boot 内嵌的tomcat 版本查看

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

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

image.png

f12点进去 查看 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版本啊

根据错误日志
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

进入目录查看C:\Users\王超凡.m2\repository\org\apache\tomcat\embed\tomcat-embed-core\9.0.39
是有9.0.39版本的

也就是说这个maven 错乱了?

在工程里强制指定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>

终于能启动正常了

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

相关阅读更多精彩内容

友情链接更多精彩内容