Spring Boot
Application Shutdown
Startup Issues
Java Development
Troubleshooting

Why does my Spring Boot app shut down immediately after starting?

Codemia Knowledge Hub ·

A Spring Boot application that starts and then exits straight away, often with no error, usually has nothing keeping it alive: no embedded web server (typically because spring-boot-starter-web is missing), no running non-daemon threads, a bean that fails during startup, or a property such as spring.main.web-application-type=none.

Reasons the app shuts down

1. No web environment

An embedded web server (Tomcat, Jetty or Undertow) or a servlet container is what normally keeps a Spring Boot application running. Without a web environment, Spring Boot runs as a plain Java application: it executes the main method, initializes all beans, and shuts down.

java
1@SpringBootApplication
2public class Application {
3
4    public static void main(String[] args) {
5        SpringApplication.run(Application.class, args);
6    }
7}

If Spring Boot detects no long-running tasks or web environment, this application closes right after launching.

2. No non-daemon threads

The JVM stays alive only while non-daemon threads are running. If the application only starts daemon threads, or all non-daemon threads finish quickly, the JVM exits. This is the normal behavior for command-line applications that run some logic and stop.

3. ApplicationContext failures

If a bean fails during initialization, for example due to misconfiguration or a missing dependency, the ApplicationContext can stop and the application shuts down.

4. Properties that disable the web server

Setting spring.main.web-application-type=none, directly or indirectly, stops Spring Boot from starting a web server.

Troubleshooting steps

  1. Check for a web dependency: Make sure pom.xml or build.gradle includes Spring Web (spring-boot-starter-web).
  2. Turn on debug logging in application.properties to get more detailed output:
 
   logging.level.org.springframework=DEBUG
  1. Review bean configuration: Look in the startup logs for exceptions or errors from beans.
  2. Inspect Application.java: Make sure it starts a server or some ongoing service.
  3. Check external configuration: Profiles and environment variables can set properties that make the application shut down.

Causes and fixes at a glance

IssueCommon CauseSolution
No web environmentMissing web dependenciesAdd spring-boot-starter-web
No active threadsAll threads are daemon threads or complete quicklyEnsure ongoing non-daemon threads
ApplicationContext issuesBeans failing during initializationFix bean configurations and dependencies
Specific configurationsProperties like spring.main.web-application-type=noneReview and adjust application.properties

Course
Intermediate
27 lessons
14 hours
OOD Fundamentals

Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.

View the course
Data Structures & Algorithms practice on Codemia

Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.

Practice algorithms