12

I am trying to build a SpringBoot application.

 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.context.ApplicationContext;

    @SpringBootApplication
    public class App {

        @SuppressWarnings("unused")
        public static void main(String[] args) throws Exception {
            ApplicationContext ctx = SpringApplication.run(App.class, args);
        }
    }

But, when I try to run the app, it throws me the below error:

2017-03-27 13:55:58.281  INFO 8608 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2017-03-27 13:55:58.299  INFO 8608 --- [           main] o.apache.catalina.core.StandardService   : Starting service Tomcat
2017-03-27 13:55:58.302  INFO 8608 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.11
2017-03-27 13:55:58.554 ERROR 8608 --- [cat-startStop-1] org.apache.catalina.core.ContainerBase   : A child container failed during start

java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].TomcatEmbeddedContext[]]
    at java.util.concurrent.FutureTask.report(FutureTask.java:122) [na:1.8.0_73]
    at java.util.concurrent.FutureTask.get(FutureTask.java:192) [na:1.8.0_73]
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:939) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:872) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1419) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_73]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_73]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_73]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_73]
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].TomcatEmbeddedContext[]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167) [tomcat-embed-core-8.5.11.jar:8.5.11]
    ... 6 common frames omitted
Caused by: org.apache.catalina.LifecycleException: Failed to start component [Pipeline[StandardEngine[Tomcat].StandardHost[localhost].TomcatEmbeddedContext[]]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5099) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [tomcat-embed-core-8.5.11.jar:8.5.11]
    ... 6 common frames omitted
Caused by: org.apache.catalina.LifecycleException: Failed to start component [org.apache.catalina.authenticator.NonLoginAuthenticator[]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.core.StandardPipeline.startInternal(StandardPipeline.java:170) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [tomcat-embed-core-8.5.11.jar:8.5.11]
    ... 8 common frames omitted
Caused by: java.lang.NoSuchMethodError: javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/String;
    at org.apache.catalina.authenticator.AuthenticatorBase.startInternal(AuthenticatorBase.java:1137) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [tomcat-embed-core-8.5.11.jar:8.5.11]
    ... 10 common frames omitted

my current pom.xml file is as follows:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>XXXX</groupId>
  <artifactId>XXXX</artifactId>
  <version>0.0.1-SNAPSHOT</version>

<!-- JSON -->
<dependency>
    <groupId>com.googlecode.json-simple</groupId>
    <artifactId>json-simple</artifactId>
    <version>1.1.1</version>
</dependency>

 <dependency>
   <groupId>commons-lang</groupId>
   <artifactId>commons-lang</artifactId>
   <version>2.2</version>
 </dependency>

<dependency>
   <groupId>com.sun.jersey</groupId>
   <artifactId>jersey-client</artifactId>
   <version>1.19.3</version>
</dependency >

<dependency>
   <groupId>com.sun.jersey</groupId>
   <artifactId>jersey-json</artifactId>
   <version>1.19.3</version>
</dependency>

<!-- REST Services  -->
  <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter</artifactId>
    <version>1.5.0.RELEASE</version>
</dependency>  

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <version>1.5.0.RELEASE</version>
</dependency>

<!-- <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
    <version>1.5.0.RELEASE</version>
</dependency> -->


  <!-- SLF4J Logging -->
  <dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>1.6.4</version>
    <scope>compile</scope>
  </dependency>  

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>jcl-over-slf4j</artifactId>
    <version>1.6.4</version>
    <scope>runtime</scope>
  </dependency>

  <dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
    <version>1.6.4</version>
    <scope>runtime</scope>
  </dependency> 

  </dependencies>

  <build>
  <sourceDirectory>src</sourceDirectory>
  <plugins>

    <!-- Set a compiler level -->
    <plugin>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>3.3</version>
      <configuration>
        <source>1.8</source>
        <target>1.8</target>
      </configuration>
    </plugin>
  </plugins>
</build>
</project>

As mentioned in some SO posts, I tried removing (Jersey), adding (embedded tomcat) dependencies. But the error seems not to be having an effect on the changes.

I also tried and another simple project (app) from Spring Tutorials (to add two numbers), this has the following pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>SpringBootDemoProject</groupId>
  <artifactId>SpringBootDemoProject</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <dependencies>
  <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter</artifactId>
    <version>1.5.0.RELEASE</version>
</dependency>  
 <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <version>1.5.0.RELEASE</version>
</dependency>

  </dependencies>
  <build>  
    <sourceDirectory>src</sourceDirectory>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.3</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

This works completely fine. Any pointers as to why this is the case?

Betafish
  • 1,212
  • 3
  • 20
  • 45
  • 2
    You have an incompatible `servlet-api.jar` in your dependency list `javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/String;`. I think you have Version 3.x but you need 2.1 – Jens Mar 27 '17 at 08:45
  • I use another library which uses **javax.servlet** internally, which is of version 3.0.1. I have modified my pom.xml file to ` javax.servlet servlet-api 2.2 ` and also added to the library ` javax.servlet javax.servlet-api `. But, the error is still the same. – Betafish Mar 27 '17 at 09:27
  • Look into the dependencies which lib is used – Jens Mar 27 '17 at 09:27

9 Answers9

7

For me, upgrading javax.servlet-api to 4.0.1 did the trick:

<dependency>
   <groupId>javax.servlet</groupId>
   <artifactId>javax.servlet-api</artifactId>
   <version>4.0.1</version>
</dependency>
Cardinal System
  • 2,749
  • 3
  • 21
  • 42
Elhanan Mishraky
  • 2,736
  • 24
  • 26
4

Looks like you have an incompatible version of Servlet API in ur classpath. This could have been as a dependencies to Jersey jars. Try pulling jersey starter from Spring boot starters.

org.springframework.boot : spring-boot-starter-jersey

This will bring the right version into your classpath.

Praneeth Ramesh
  • 3,434
  • 1
  • 28
  • 34
  • 1
    This was a helpful clue for me. I solved this issue by excluding all transitive servlet dependencies – JMess Mar 15 '18 at 19:57
1

My guess is you have to use the default ServletInitializer class that is provided within the Spring Boot Project template of Eclipse.

//SpringBootApplication.java
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class SpringBootApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringBootApplication.class, args);
    }
}

//ServletInitializer.java
public class ServletInitializer extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(SpringBootApplication.class);
    }

}

If you are not using ServletInitializer class as specified in Spring Boot Starter Project template, try to extend SpringBootServletInitializer from your App class

public class App extends SpringBootServletInitializer

Please check a similar answer here

somnathchakrabarti
  • 3,026
  • 10
  • 69
  • 92
1

I just remove my (tomcat-embed-jasper ) , it's worked for me .

  • I just remove the version of (tomcat-embed-jasper ) , it's worked for me – Swetaparna Jena Sep 08 '22 at 10:21
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Sep 13 '22 at 02:39
1

I had the same problem with a different cause.

I was trying to run a project on Eclipse and I received this error, and my problem was the version of JDK chosen to run the project.

Run configuration with JDK

I had to set my run configuration to 1.8, same as project.

0

I solved this problem using tomcat configuration in pom.xml

First go to tomcat folder and open cmd in bin my path is :

C:\Program Files\Apache Software Foundation\Tomcat 8.5\bin>

get tomcat version using this command

C:\Program Files\Apache Software Foundation\Tomcat 8.5\bin>catalina.sh version

enter image description here

After this add this in pom.xml

<properties>
        <java.version>1.8</java.version>
        <tomcat.version>8.5.43</tomcat.version>
</properties>
Abd Abughazaleh
  • 4,615
  • 3
  • 44
  • 53
0

It was solution for me after 2 days, just add this part to pom.xml

<plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-surefire-plugin</artifactId>
     <version>2.22.2</version>
     <configuration>
         <skipTests>true</skipTests>
     </configuration>
 </plugin>
-1
   <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-jasper</artifactId>
        <version>9.0.44</version>
    </dependency>
  • 1
    Please read [How do I write a good answer?](https://stackoverflow.com/help/how-to-answer). While this code block may answer the OP's question, this answer would be much more useful if you explain how this code is different from the code in the question, what you've changed, why you've changed it and why that solves the problem without introducing others. - [From Review](https://stackoverflow.com/review/low-quality-posts/32238228) – Saeed Zhiany Jul 18 '22 at 05:18
-3

I had the same issue, After commenting out the below it was fixed. One of the follwoing dependency was the culprit.

    <!--  dependency>
    <groupId>me.fhir</groupId>
    <artifactId>fhir</artifactId>
    <version>0.12.0-RELEASE</version>
</dependency-->
<!--  dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.8.8</version>
</dependency-->
<!-- dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-core</artifactId>
    <version>2.8.8</version>
</dependency-->
Buminda
  • 611
  • 8
  • 15