Why does my Spring Boot App always shutdown immediately after starting?
Resolution: the app is not a webapp because it doesn't have an embedded container (e.g. Tomcat) on the classpath. Adding one fixed it. If you are using Maven, then add this in pom.xml
:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
For Gradle (build.gradle
) it looks like
dependencies {
compile 'org.springframework.boot:spring-boot-starter-web'
}
I had the same problem but when I removed
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
it started working again.
Here is how you can fix it:
Check if you don't have dependency on spring-boot-starter-web in your pom.xml file. To get you pom.xml file right, use this link start.spring.io
If you have above dependency, but still facing the issue, it is highly possible that your embedded tomcat jars are present. To confirm this, run maven build in debug mode -
mvn spring-boot:run --debug
and look for messages like -
[WARNING] error reading /Users/sparrowmac1/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/8.5.20/tomcat-embed-core-8.5.20.jar; invalid LOC header (bad signature) [WARNING] error reading /Users/sparrowmac1/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.8.10/jackson-core-2.8.10.jar; invalid LOC header (bad signature)
If such messages are present, purge your local maven repo and try again -
mvn dependency:purge-local-repository