Why Does My Spring Boot App Always Shutdown Immediately 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>

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

Why does my Spring Boot app shutdown by itself

I know why: because I start my Spring Boot webapp using

java -jar xxx.jar

but when I start it by

nohup java -jar xxx.jar

the application will run correct and won't be terminated when the SSH session terminates.

From https://linux.101hacks.com/unix/nohup-command/

When you execute a Unix job in the background ( using &, bg command), and logout from the session, your process will get killed. You can avoid this using several methods — executing the job with nohup, or making it as batch job using at, batch or cron command.

Spring Boot 2.4.3 application immediately shuts down after starting

Your code works. I do not have Java 15, I have changed it to use 11 and it runs.

This is what I have got:

  .   ____          _            __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.4.3)

2021-03-17 23:15:01.495 INFO 34616 --- [ main] com.example.demo.DemoApplication : Starting DemoApplication using Java 11.0.3 on machine1.domain.com with PID 34616 (/Users/test/Downloads/demo 5/out/production/demo started by test in /Users/test/Downloads/demo 5)
2021-03-17 23:15:01.497 INFO 34616 --- [ main] com.example.demo.DemoApplication : No active profile set, falling back to default profiles: default
2021-03-17 23:15:02.192 INFO 34616 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2021-03-17 23:15:02.199 INFO 34616 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2021-03-17 23:15:02.199 INFO 34616 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.43]
2021-03-17 23:15:02.251 INFO 34616 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2021-03-17 23:15:02.251 INFO 34616 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 711 ms
2021-03-17 23:15:02.362 INFO 34616 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2021-03-17 23:15:02.495 INFO 34616 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2021-03-17 23:15:02.508 INFO 34616 --- [ main] com.example.demo.DemoApplication : Started DemoApplication in 1.249 seconds (JVM running for 1.977)

JDK 15 might be 'too new'. If you are just experimenting, downgrade JDK to a lower one. Java 11 has long-term support.



Related Topics



Leave a reply



Submit