Spring Boot Application Shutdown Immediate After Starting

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'
}

Spring Boot Application immediately shuts down after starting

Problem is solved - thanks for your help crazycoder.
The issue was caused by an older version of tomcat. After upating the embedded tomcat of Spring to 1.5.3_RELEASE and updating mysql-jdbc-driver as well , it finally worked for me.
I adjusted the pom.xml like this:

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
</parent>

spring-boot application shutdown immediately after starting (schedular)

While Spring Boot enables a lot of things depending on your dependencies it doesn't do so for scheduling and async. You still need to manually enable that by adding, respectively, @EnableScheduling and @EnableAsync.

In your case adding @EnableScheduling to your application class is enough.

@SpringBootApplication
@EnableScheduling
public class SpringSchedularApplication {

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

With this scheduling will be enabled and because there is a scheduling thread still running the application won't shutdown.

Why does my Spring Boot application shuts down as soon as I run it?

I think that this is causing trouble and you should remove it

        <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>

You have this one that has the Tomcat already embedded

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

So a brief overview on why you faced the issue:

You tried to use an external tomcat and specified to your application that you will provide it to it by the runtime <scope>provided</scope> check it here. But the application already has it embedded in it, and spring-boot by default creates a jar file, the tomcat needs a war file. In addition, the tomcat server won't launch your main method, you need to start your application as a normal spring app.

To use an external tomcat server follow these steps:

  1. Set the packing to generate war

    <packaging>war</packaging>

  2. Add the external tomcat dependency

        <dependency>
<groupid>org.springframework.boot</groupid>
<artifactid>spring-boot-starter-tomcat</artifactid>
<scope>provided</scope>
</dependency>

  1. Exclude the embedded tomcat from the spring-boot-starter-web
<dependency>
<groupid>org.springframework.boot</groupid>
<artifactid>spring-boot-starter-web</artifactid>
<exclusions>
<exclusion>
<groupid>org.springframework.boot</groupid>
<artifactid>spring-boot-starter-tomcat</artifactid>
</exclusion>
</exclusions>
</dependency>

And make a bunch of configurations to make it start as a Spring app and add the external configuration of your spring boot app on tomcat.

Check this article here I think it will complete the whole idea. link



Related Topics



Leave a reply



Submit