0

在eclipse中声明新服务器并运行它之后..tomcat 7无法启动并在控制台中打印:

Starting Servlet Engine: Apache Tomcat/7.0.12
java.lang.NoSuchMethodError: javax.servlet.ServletContext.getSessionCookieConfig()Ljavax/servlet/SessionCookieConfig;
    at org.apache.catalina.deploy.WebXml.configureContext(WebXml.java:1281)
    at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1332)
    at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:882)
    at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:317)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:89)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5081)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1033)
    at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:774)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1033)
    at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:291)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
    at org.apache.catalina.core.StandardService.startInternal(StandardService.java:443)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
    at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:727)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:620)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:303)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:431)
4

1 回答 1

0

正如其他人所指出的,您的类路径中可能有旧版本servlet-api.jar。您可以打开详细类加载(VM 参数-verbose:class)以查看从哪个 .jar 文件javax.servlet.ServletContext加载。Tomcat 7 使用 API 版本 3.0。在我们的(测试)案例中,类路径中有 2.4 版;在surefire插件(我们是基于Maven的)的测试类路径中排除它工作,即<classpathDependencyExcludes>javax.servlet:servlet-api</classpathDependencyExcludes>. Tomcat 7 然后选择了自己的兼容版本。如果您需要在类路径中有 .jar,您可以获得与这些 Maven 工件坐标兼容的 .jar javax.servlet:javax.servlet-api:3.0.1

于 2013-03-05T18:11:07.517 回答