SpringBoot启动问题

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/m0_37354861/article/details/71439063

1、初次使用SpringBoot的同学们可能运行时会碰到java.lang.NoSuchMethodError: javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/String异常的信息,此时可能是你tomcat版本冲突导致。

我本地的Tomcat版本是7,Springboot内置版本是8

java.lang.NoSuchMethodError: javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/String;
	at org.apache.tomcat.websocket.server.WsServerContainer.<init>(WsServerContainer.java:149) ~[tomcat-embed-websocket-8.0.33.jar:8.0.33]
	at org.apache.tomcat.websocket.server.WsSci.init(WsSci.java:131) ~[tomcat-embed-websocket-8.0.33.jar:8.0.33]
	at org.apache.tomcat.websocket.server.WsContextListener.contextInitialized(WsContextListener.java:39) ~[tomcat-embed-websocket-8.0.33.jar:8.0.33]
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4811) [tomcat-embed-core-8.0.33.jar:8.0.33]
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5251) [tomcat-embed-core-8.0.33.jar:8.0.33]
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147) [tomcat-embed-core-8.0.33.jar:8.0.33]
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408) [tomcat-embed-core-8.0.33.jar:8.0.33]
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398) [tomcat-embed-core-8.0.33.jar:8.0.33]
	at java.util.concurrent.FutureTask.run(FutureTask.java:262) [na:1.7.0_79]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [na:1.7.0_79]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [na:1.7.0_79]
	at java.lang.Thread.run(Thread.java:745) [na:1.7.0_79]
SpringBoot所依赖的jar包和你本地的tomcat版本不一致导致,Spring运行首先会匹配本地的tomcat,需要和本地tomcat版本保持一致,如果时maven管理则需要将pom.xml中加入
<properties>
  <tomcat.version>7.0.52</tomcat.version>

</properties>

重新启动,问题可以解决





展开阅读全文

没有更多推荐了,返回首页