IntelliJ Process finished with exit code 0 when spring-boot run – Spring

Photo of author
Written By M Ibrahim
intellij-idea spring spring-boot

Quick Fix: Eliminate provided scope from spring-boot-starter-tomcat dependency in your pom.xml file, as this scope is not needed in a Spring Boot application.

The Problem:

IntelliJ Process finished with exit code 0 when spring-boot run. There is a warning during application startup about Cache 'publicationsCount' is set to eternal but also has TTI/TTL set.

The Solutions:

Solution 1: Removing `provided` scope of `spring-boot-starter-tomcat` dependency

The issue with the Spring Boot application starting in IntelliJ IDEA, but not in the terminal, may be related to the `provided` scope of the `spring-boot-starter-tomcat` dependency in the project’s Maven or Gradle build configuration.

The `provided` scope indicates that the dependency is only needed for compilation and testing, and it won’t be included in the final packaged application. This can be useful for dependencies that are already provided by the runtime environment, such as the servlet container (Tomcat in this case).

However, when running the application from IntelliJ IDEA, it may not have access to the same provided dependencies as the terminal environment. This can lead to issues when the application attempts to use the provided dependency, such as Tomcat, during runtime.

To resolve this issue, removing the `provided` scope from the `spring-boot-starter-tomcat` dependency can ensure that it is included in the final packaged application. This will allow both IntelliJ IDEA and the terminal environment to have access to the necessary dependencies for running the application.

Here’s an example of removing the `provided` scope from the `spring-boot-starter-tomcat` dependency in a Maven project:

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

<!-- Updated configuration -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>

After making this change, rebuild the project and try running the application again in IntelliJ IDEA. This should resolve the issue related to the process exiting with code 0.

Solution 2: Ensure Key Dependencies Installation

To resolve this issue and successfully run your Spring Boot application, you should ensure that you have the following key dependencies installed in your project:

  1. Spring Boot Web Starter Dependency:
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    

    This dependency enables essential web components, including the Servlet and Spring MVC frameworks, allowing your application to process HTTP requests.

  2. Spring Security Starter Dependency:
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    

    This dependency integrates Spring Security into your application, providing features such as user authentication and authorization.

By ensuring the presence of these key dependencies in your project, you can successfully run your Spring Boot application without encountering the mentioned error.

Solution 3: Adding spring boot starter web

The issue was resolved by including the `spring-boot-starter-web` dependency. This dependency provides the necessary classes and configurations for creating a web application. Adding this dependency ensures that the Spring Boot application has the necessary components to handle HTTP requests and responses. Without it, the application may not be able to start properly when run through IntelliJ, leading to the error message “Process finished with exit code 0,”.

The `spring-boot-starter-web` dependency can be added to the project’s pom.xml file. Here’s an example of how to include it:

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

After adding this dependency, rebuild the project and try running the application again. It should now start successfully without the error message.

Including the `spring-boot-starter-web` dependency is a common step when creating a new Spring Boot application. It provides the necessary infrastructure for handling web requests, making it easier to develop web applications using Spring Boot.

Solution 4: Add dependency

When creating a project using the Gradle template from https://start.spring.io/, you need to add the `org.springframework.boot:spring-boot-starter-web` dependency to your build.gradle file. This dependency is essential for running a Spring Boot application correctly.

To add the dependency, open your build.gradle file and locate the `dependencies` block. Add the following line within the block:

implementation 'org.springframework.boot:spring-boot-starter-web'

Save the build.gradle file and rebuild your project. This should resolve the issue and allow you to run your Spring Boot application from IntelliJ without encountering the “Process finished with exit code 0” error.

Solution 5: Add the required dependencies to your project

To resolve the issue where IntelliJ process exits with code 0 when running a Spring Boot application, you need to add the following dependencies to your project’s pom.xml file:

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

These dependencies are required for Spring Boot applications to run properly. By adding them to your project, you will be able to successfully run your application from within IntelliJ.