获取 NoSuchMethodError:javax.servlet.ServletContext.getVirtualServerName() [英] Getting NoSuchMethodError:javax.servlet.ServletContext.getVirtualServerName()
问题描述
我在 Tomcat 8 中部署服务时遇到问题.出现以下错误:
I am facing an issue during deployment of a service in Tomcat 8. Getting following error :
引起:java.lang.NoSuchMethodError:javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/String;在 org.apache.tomcat.websocket.server.WsServerContainer.(WsServerContainer.java:149)在 org.apache.tomcat.websocket.server.WsSci.init(WsSci.java:131)在 org.apache.tomcat.websocket.server.WsSci.onStartup(WsSci.java:47)在 org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5244)在 org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)……还有 10 个
Caused by: java.lang.NoSuchMethodError: javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/String; at org.apache.tomcat.websocket.server.WsServerContainer.(WsServerContainer.java:149) 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:5244) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ... 10 more
方法 getVirtualServerName
是在 Servlet 3.1 中引入的,在从我的 servlet-api
jar 中提取 MANIFEST.MF
后,我得到了以下详细信息:>
Method getVirtualServerName
was introduced in Servlet 3.1 and after extracting MANIFEST.MF
from my servlet-api
jar I got following details :
Specification-Title: Java API for Servlets
Specification-Version: 3.1
Specification-Vendor: Sun Microsystems, Inc.
Implementation-Title: javax.servlet
也就是说它有 3.1.那么这个错误还有其他原因吗?请帮忙
Which says that its having 3.1. So is there any other reason for this error? Please help
推荐答案
检查您的所有 Maven(或等效项)依赖项,并确保您——或者很可能是另一个依赖项——没有引入 3.1 之前的 javax.servlet/servlet-api
可能优先于 Tomcat 8 中的内容.如果您已手动部署,请确保您没有将任何 servlet-api JAR 手动复制到 Tomcat 本身中.
Check all your Maven (or equivalent) dependencies and make sure that you - or most likely another dependency - are not pulling in a pre-3.1 version of the javax.servlet / servlet-api
that may be taking precedence over what's in your Tomcat 8. If you've manually deployed, make sure you haven't manually copied any servlet-api JARs into Tomcat itself.
参见:https://stackoverflow.com/a/26232535/954442
这篇关于获取 NoSuchMethodError:javax.servlet.ServletContext.getVirtualServerName()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!