Tomcat 8.0 won't start with pure Spring MVC te

2019-07-23 18:53发布

I have created a template Spring MVC project template using STS 3.7.3 and jdk 1.8.

I run generated code on Pivotal tc Server Developer Edition provided on STS 3.7.3. The server started and application is deployed and the Hello world page is shown.

However when I add tomcat 8.0 server (which starts successfully without any deployed app) and start to deploy exactly same application I get:

SEVERE: A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/core]]
    at java.util.concurrent.FutureTask.report(Unknown Source)
    at java.util.concurrent.FutureTask.get(Unknown Source)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:915)
    at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:871)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1407)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1397)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/core]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:153)
    ... 6 more
Caused by: java.lang.NullPointerException
    at org.apache.jasper.servlet.TldScanner$TldScannerCallback.scanWebInfClasses(TldScanner.java:401)
    at org.apache.tomcat.util.scan.StandardJarScanner.scan(StandardJarScanner.java:208)
    at org.apache.jasper.servlet.TldScanner.scanJars(TldScanner.java:262)
    at org.apache.jasper.servlet.TldScanner.scan(TldScanner.java:106)
    at org.apache.jasper.servlet.JasperInitializer.onStartup(JasperInitializer.java:103)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5261)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
    ... 6 more

maj 25, 2016 2:36:25 PM org.apache.catalina.core.ContainerBase startInternal
SEVERE: A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost]]
    at java.util.concurrent.FutureTask.report(Unknown Source)
    at java.util.concurrent.FutureTask.get(Unknown Source)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:915)
    at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
    at org.apache.catalina.core.StandardService.startInternal(StandardService.java:441)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
    at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:787)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:629)
    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:351)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:485)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:153)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1407)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1397)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: org.apache.catalina.LifecycleException: A child container failed during start
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:923)
    at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:871)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
    ... 6 more

maj 25, 2016 2:36:25 PM org.apache.catalina.startup.Catalina start
SEVERE: The required Server component failed to start so Tomcat is unable to start.
org.apache.catalina.LifecycleException: Failed to start component [StandardServer[8005]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:153)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:629)
    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:351)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:485)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardService[Catalina]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:153)
    at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:787)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
    ... 7 more
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:153)
    at org.apache.catalina.core.StandardService.startInternal(StandardService.java:441)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
    ... 9 more
Caused by: org.apache.catalina.LifecycleException: A child container failed during start
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:923)
    at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
    ... 11 more

maj 25, 2016 2:36:25 PM org.apache.coyote.AbstractProtocol pause
INFO: Pausing ProtocolHandler ["http-nio-8080"]
maj 25, 2016 2:36:25 PM org.apache.coyote.AbstractProtocol pause
INFO: Pausing ProtocolHandler ["ajp-nio-8009"]
maj 25, 2016 2:36:25 PM org.apache.catalina.core.StandardService stopInternal
INFO: Stopping service Catalina
maj 25, 2016 2:36:25 PM org.apache.coyote.AbstractProtocol destroy
INFO: Destroying ProtocolHandler ["http-nio-8080"]
maj 25, 2016 2:36:25 PM org.apache.coyote.AbstractProtocol destroy
SEVERE: Failed to destroy end point associated with ProtocolHandler ["http-nio-8080"]
java.lang.NullPointerException
    at org.apache.tomcat.util.net.NioEndpoint.releaseCaches(NioEndpoint.java:316)
    at org.apache.tomcat.util.net.NioEndpoint.unbind(NioEndpoint.java:492)
    at org.apache.tomcat.util.net.AbstractEndpoint.destroy(AbstractEndpoint.java:821)
    at org.apache.coyote.AbstractProtocol.destroy(AbstractProtocol.java:534)
    at org.apache.catalina.connector.Connector.destroyInternal(Connector.java:1023)
    at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:297)
    at org.apache.catalina.core.StandardService.destroyInternal(StandardService.java:589)
    at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:297)
    at org.apache.catalina.core.StandardServer.destroyInternal(StandardServer.java:877)
    at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:297)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:633)
    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:351)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:485)

maj 25, 2016 2:36:25 PM org.apache.coyote.AbstractProtocol destroy
INFO: Destroying ProtocolHandler ["ajp-nio-8009"]
maj 25, 2016 2:36:25 PM org.apache.coyote.AbstractProtocol destroy
SEVERE: Failed to destroy end point associated with ProtocolHandler ["ajp-nio-8009"]
java.lang.NullPointerException
    at org.apache.tomcat.util.net.NioEndpoint.releaseCaches(NioEndpoint.java:316)
    at org.apache.tomcat.util.net.NioEndpoint.unbind(NioEndpoint.java:492)
    at org.apache.tomcat.util.net.AbstractEndpoint.destroy(AbstractEndpoint.java:821)
    at org.apache.coyote.AbstractProtocol.destroy(AbstractProtocol.java:534)
    at org.apache.catalina.connector.Connector.destroyInternal(Connector.java:1023)
    at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:297)
    at org.apache.catalina.core.StandardService.destroyInternal(StandardService.java:589)
    at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:297)
    at org.apache.catalina.core.StandardServer.destroyInternal(StandardServer.java:877)
    at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:297)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:633)
    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:351)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:485)

From what I read problem might be related to version issue of servlet-api.jar which is included in my pom.xml however I thought that adding scope:provided should solve the issue (It does not).

Can anyone give me a hint what I am doing wrong?

2条回答
何必那么认真
2楼-- · 2019-07-23 19:13

Did you try to add your servlet jar file to WEB-INF/lib.

I was also get same exception while deploying my spring mvc project.

This is my servlet definition in web.xml;

<servlet>
        <servlet-name>appServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

Here, org.springframework.web.servlet.DispatcherServlet belongs to spring-mvc-X.Y.Z.jar. (Mine is spring-mvc-4.2.5.RELEASE.jar). I copied this jar from MavenDependencies and paste into the WEB-INF/lib folder. Then re-deploy war file to the server and everything is ok.

Note that, if there is no lib folder under WEB-INF, you should create yourself.

查看更多
\"骚年 ilove
3楼-- · 2019-07-23 19:24

The relevant part of this stack trace is:

Caused by: java.lang.NullPointerException
    at org.apache.jasper.servlet.TldScanner$TldScannerCallback.scanWebInfClasses(TldScanner.java:401)
    at org.apache.tomcat.util.scan.StandardJarScanner.scan(StandardJarScanner.java:208)
    at org.apache.jasper.servlet.TldScanner.scanJars(TldScanner.java:262)
    at org.apache.jasper.servlet.TldScanner.scan(TldScanner.java:106)
    at org.apache.jasper.servlet.JasperInitializer.onStartup(JasperInitializer.java:103)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5261)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
    ... 6 more

A bug was introduced in Tomcat 8.0.35 (Released May 16, 2016) - the TldScannerCallback.scanWebInfClasses method was changed to rely on the getResourcePaths method. It was fixed in Tomcat 8.0.36 (Released June 9, 2016).

In case it helps others find this answer, I only just now encountered this problem after doing a minor version upgrade from Tomcat 8.0.32 to 8.0.35 (Amazon EC2 instances pushed the 8.0.35 update this morning). In my case, a web application that has been working without modifications since Tomcat 5 was broken by this update.

I was able to work around the problem using the recommendation in the above bug report. Specifically, an empty WEB-INF/classes/META-INF folder was triggering this bug, so I created a MANIFEST.MF file in that folder.

Here is the commit that introduced the bug, and here is the commit that fixed the bug, where the committer refers to it as a "rare NPE case", whatever that means (implies that folders are rarely empty?). After reading the annotations in the commits, it is apparent that this was a hack to suppress a FindBugs report in working code, which in turn produced a real bug that breaks web applications.

查看更多
登录 后发表回答