在春季启动中从XML迁移到Java配置时,我收到了以下错误。
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.32.jar:8.0.32]
at org.apache.tomcat.websocket.server.WsSci.init(WsSci.java:131) ~[tomcat-embed-websocket-8.0.32.jar:8.0.32]
at org.apache.tomcat.websocket.server.WsContextListener.contextInitialized(WsContextListener.java:39) ~[tomcat-embed-websocket-8.0.32.jar:8.0.32]
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4812) [tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5255) [tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147) [tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408) [tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398) [tomcat-embed-core-8.0.32.jar:8.0.32]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_172]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_172]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_172]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_172]
当我从SpringBootServletInitializer
扩展类中删除@ImportResource("classpath:applicationContext.xml")
时,会出现此错误。
我已经检查了pom依赖层次结构中的servlet api版本,它被设置为3.0.1,并且只有一个servlet api依赖,并且没有冲突的较低版本。
我使用的是春季启动版本1.3.3.RELEASE
。
getVirtualServerName已添加到Servlet 3.1的Servlet上下文中。
请将servlet api更新到最新版本。