Java Tomcat 9.0.12版的启动问题
我试图在运行jre 1.8的tomcat 9.0.12版和Eclipse Oxygen上部署应用程序 但我经常遇到以下例外情况Java Tomcat 9.0.12版的启动问题,java,tomcat,Java,Tomcat,我试图在运行jre 1.8的tomcat 9.0.12版和Eclipse Oxygen上部署应用程序 但我经常遇到以下例外情况 Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[]] at org.apache.catalina.util.Lifecycl
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[]]
at org.apache.catalina.util.LifecycleBase.handleSubClassException(LifecycleBase.java:441)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:198)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1429)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1419)
at java.util.concurrent.FutureTask.run(Unknown Source)
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
at java.util.concurrent.AbstractExecutorService.submit(Unknown Source)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:944)
... 21 more
Caused by: java.lang.NoSuchMethodError: javax.servlet.ServletContext.getClassLoader()Ljava/lang/ClassLoader;
我的类路径中有一个servlet-api-2.5.jar
,它有getClassLoader
方法。不知道我做错了什么
有人能帮我找到一个解决方案吗。请说明您的声明如果servlet-api-2.5.jar中的
ServletContext
确实包含文件名所建议的servlet 2.5规范,那么它就不能有问题的方法
ServletContext.getClassLoader
是在servlet规范的3.0版中引入的:
/**
* Get the web application class loader associated with this ServletContext.
*
* @return The associated web application class loader
*
* @throws UnsupportedOperationException If called from a
* {@link ServletContextListener#contextInitialized(ServletContextEvent)}
* method of a {@link ServletContextListener} that was not defined in a
* web.xml file, a web-fragment.xml file nor annotated with
* {@link javax.servlet.annotation.WebListener}. For example, a
* {@link ServletContextListener} defined in a TLD would not be able to
* use this method.
* @throws SecurityException if access to the class loader is prevented by a
* SecurityManager
* @since Servlet 3.0
*/
public ClassLoader getClassLoader();
同样,您不应该用不同的ServletAPI版本污染您的类路径
Tomcat已经附带了在ApacheTomcat/lib目录中提供的正确的ServletAPI.jar
。您不应该将该jar的任何版本添加到web应用程序中。如果您使用的是maven,您可以在提供的范围中添加对servlet 4 api的引用,这样您的IDE和构建工具knwo将在运行时可用,但不能随工件一起提供:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<scope>provided</scope>
</dependency>
javax.servlet
javax.servlet-api
4.0.1
假如
或者完全匹配所选Apache Tomcat版本:
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-servlet-api</artifactId>
<version>9.0.12</version>
<scope>provided</scope>
</dependency>
org.apache.tomcat
TomcatServletAPI
9.0.12
假如
看起来您没有导入正确的库。给我们你的密码。至少进口statements@RoshanaPitigala导入javax.servlet.ServletConfig;导入javax.servlet.ServletException;导入javax.servlet.http.HttpServlet;我尝试分别使用servlet-api-2.5.jar和javax.servlet.jar编译和部署。但仍然以相同的例外情况结束。@Bopanna如果下面的一个是您问题的答案,您可以标记已回答的问题。