Tomcat启动失败:java.lang.NoSuchMethodError: org.apache.tomcat.util.res.StringManager.getManager(Ljava/lang/Class;)Lorg/apache/tomcat/util/res/StringManager
项目开发中发现服务器上Tomcat启动失败
开始定位
第一步:打开tomcat日志catalina.log:
2017-07-25 17:02:43,799 [Catalina-startStop-1] ERROR org.apache.catalina.core.ContainerBase - A child container failed during start java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/yxicadmin]] at java.util.concurrent.FutureTask.report(FutureTask.java:122) at java.util.concurrent.FutureTask.get(FutureTask.java:188) at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1122) at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:819) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1574) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1564) at java.util.concurrent.FutureTask.run(FutureTask.java:262) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745) Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/yxicadmin]] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154) ... 6 more Caused by: java.lang.NoSuchMethodError: org.apache.tomcat.util.res.StringManager.getManager(Ljava/lang/Class;)Lorg/apache/tomcat/util/res/StringManager; at org.apache.tomcat.websocket.WsWebSocketContainer.<clinit>(WsWebSocketContainer.java:77) at org.apache.tomcat.websocket.server.WsSci.init(WsSci.java:131) at org.apache.tomcat.websocket.server.WsSci.onStartup(WsSci.java:47) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5506) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ... 6 more 2017-07-25 17:02:43,802 [main] ERROR org.apache.catalina.core.ContainerBase - A child container failed during start java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost]] at java.util.concurrent.FutureTask.report(FutureTask.java:122) at java.util.concurrent.FutureTask.get(FutureTask.java:188) at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1122) at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:300) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.StandardService.startInternal(StandardService.java:443) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:739) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.startup.Catalina.start(Catalina.java:689) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
找到关键点:java.lang.NoSuchMethodError: org.apache.tomcat.util.res.StringManager.getManager(Ljava/lang/Class;)Lorg/apache/tomcat/util/res/StringManager;
虽然不清楚是什么原因,不过很奇怪的是本地项目是能跑起来的。看了下测试机tomcat版本是7.0.56,本地是7.0.68,难道和这个有关?
第二步:判断是否和tomcat版本有关:
下载了一个7.0.56版本的tomcat,在本地运行,果不其然,也复现了该错误。然而是不是和tomcat有关呢?这个不不能确定,但是有一点是可以肯定的,测试机tomcat版本替换难度较大,而且还要所有环境版本同步,这个代价较大,因此转换思路,是否是类冲突了呢。。
开始百度
第三步:发现关键原因:类冲突
网上查找类似错误,有前辈遇到了,并且分析了原因:Springboot内嵌tomcat8,与tomcat7冲突,突然意识到这个需求引入了部门其他同事提供的Jar包,难道是那个Jar包导致的。。
OK,那我们验证下,先使用maven命令:mvn dependency:tree 输出下maven依赖树:
发现关键点:
[INFO] +- com.xxx.xxx.xx:xxx-client:jar:1.0-SNAPSHOT:compile [INFO] | +- com.netease.mail.dp:dqs-model:jar:1.0-SNAPSHOT:compile [INFO] | +- org.apache.commons:commons-lang3:jar:3.4:compile [INFO] | +- commons-httpclient:commons-httpclient:jar:3.1:compile [INFO] | +- org.springframework.boot:spring-boot-starter-web:jar:1.5.1.RELEASE:compile [INFO] | | \- org.springframework.boot:spring-boot-starter:jar:1.5.1.RELEASE:compile [INFO] | | +- org.springframework.boot:spring-boot:jar:1.5.1.RELEASE:compile [INFO] | | +- org.springframework.boot:spring-boot-autoconfigure:jar:1.5.1.RELEASE:compile [INFO] | | \- org.springframework.boot:spring-boot-starter-logging:jar:1.5.1.RELEASE:compile
果然,这个XXXJar包引用了org.springframework.boot:spring-boot-starter-web
试着使用网上的办法去掉spring-boot-starter-web依赖的spring-boot-starter-tomcat Jar包,没用
于是直接粗暴点:
<dependency> <groupId>com.xxx.xxx.xxx</groupId> <artifactId>xxx-client</artifactId> <version>1.0-SNAPSHOT</version> <exclusions> <exclusion> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-core</artifactId> </exclusion> <exclusion> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-el</artifactId> </exclusion> <exclusion> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-websocket</artifactId> </exclusion> </exclusions> </dependency>
重新打包运行,问题解决。