Learn to solve the issue in IntelliJ, when we run a Spring boot application and after the start, the application shuts down automatically with the exit code 0, i.e. without any error in the console.
1. Problem
We faced this issue while running a Spring boot application in IntelliJ. When we run the application, it starts normally but closes as soon as the application was UP. Although, a clearly visible issue was that embedded Tomcat was not starting.
The application logs were like this:
... c.h.ResourceServerApplication : Starting ResourceServerApplication using Java 17.0.1 with PID 22648 (...\target\classes started by lokesh in ...\IdeaProjects\Spring-security)
... c.h.ResourceServerApplication : No active profile set, falling back to 1 default profile: "default"
... c.h.ResourceServerApplication : Started ResourceServerApplication in 2.046 seconds (process running for 2.399)
Process finished with exit code 0
2. Solutions
2.1. Check Maven Home Path
This was the exact problem with my machine. The Maven home was referring to Bundled (Maven 3). After pointing it to the local Maven installation, the application started correctly and Tomcat was started successfully.
To check the Maven home path, go to Settings (CTRL + ALT + S) or navigate to File -> Settings. Change the path to the local Maven installation folder.

2.2. Include Web Starter Dependency
If not included till now, you must add the spring-boot-starter-web
dependency in the pom.xml file. It transitively includes the spring-boot-starter-tomcat
in complie
scope.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
2.3. Embedded Tomcat Scope
If you have the spring-boot-starter-tomcat dependency added in pom.xml check out its scope. If we are using <packaging>jar</packaging>
then the scope must be ‘compile’. Do not use the ‘provided’ scope.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>compile</scope>
</dependency>
The ‘provided’ scope is suitable for ‘war’ packaging when we deploy the application to an external dedicated Tomcat application server.
3. Conclusion
In this quick tutorial, we learned the most common solutions for the Spring boot application closing automatically after restart, and not throwing any error with exit code 0.
Happy Learning !!
Comments