I am getting below exception when I am trying to run a Spring MVC application using Spring boot...
ContainerBase: A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[]]
at java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.util.concurrent.FutureTask.get(FutureTask.java:188)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1123)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:799)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
... 6 more
Caused by: java.lang.NoSuchMethodError: javax.servlet.ServletContext.addServlet(Ljava/lang/String;Ljavax/servlet/Servlet;)Ljavax/servlet/ServletRegistration$Dynamic;
at org.springframework.boot.context.embedded.ServletRegistrationBean.onStartup(ServletRegistrationBean.java:166)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext$1.onStartup(EmbeddedWebApplicationContext.java:214)
at org.springframework.boot.context.embedded.tomcat.ServletContextInitializerLifecycleListener.lifecycleEvent(ServletContextInitializerLifecycleListener.java:54)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5355)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 6 more
I solved it excluding a transitive servlet-api dependency.
In my case, it was com.github.isrsal:spring-mvc-logger
I was using Gradle and what worked for me:
It trimmed dependency tree in desired way.
For anyone else who couldn't solve it by excluding
servlet-api
, here is an alternative:It turns out Spring Boot defaults to Tomcat 8. If you're running a different version of Tomcat and would like to fix this error, just add your tomcat version to the pom properties:
If you want to find out where the class is being loaded from, try
where
foo.jar
is the fat JAR produced by Gradle or Maven. For example, theServletContext
class could be getting read from an olderservlet-api
JAR in a JDK extensions directory instead of your Maven or Gradle dependencies.The output of the command looks something like this...
I was running with Hadoop 2.7.2 using Spring-boot, the following Hadoop dependencies uses javax.servlet which prevented the embedded tomcat version to start. Below exclusions in my POM fixed the issue.
I couldn't track down the problematic reference except for knowing it is somehow getting into my class-path so here is my 2 cents for lazy developers using eclipse:
Scroll down the list of maven dependencies under your project tree (usually under Java Resources -> Libraries -> Maven Dependencies), track the problematic added jar you wish to exclude from your packaged JAR, right click on it -> select Maven -> Exclude Maven Artifact ! Voila - automatically an exclusion will be added to your pom right under the dependency that refers it.
Mine BTW was jcifs...
Good luck!