Springboot Application exits immediately

13,230

Solution 1

Because of you spring boot in pom.xml you did not declare as starter web project it will shut down immediately, it is an expected behavior, now to run as web container you need to add below code in your pom.xml.

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

Solution 2

I've just have the problem with IntelliJ (even with the spring-boot-starter-web) and solve it by editing the launcher and check Include dependencies with "Provided" scope option.

The web app was working fine from the command line.

Solution 3

I don't see any issues with this.

Process finished with exit code 0

This says process ended happily.

Given your application is not having spring-boot-starter-web dependency then it won't be starting any server and not waiting for any request.

It is very much similar to a main method which does not have anything to execute or finishes as soon as main code completes.

Solution 4

I just had the same problem. None of the dependencies like spring-boot-starter-web or removing dependency spring-boot-starter-tomcat didn't work. I was using IntelliJ Idea IDE community version. I think it is something to do with the IntelliJ Idea Community Version, as they mention that spring is not supported in the community version, only in the ultimate (commercial) version, at least for mac.

https://www.jetbrains.com/idea/download/#section=mac

The reason of my thinking because I switched to visual studio code, installed the necessary plugins for spring boot and it worked out of the box, with my existing pom.xml file.

My current dependencies are:

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

May be worth to mention that also works without the spring-boot-starter-tomcat dependency.

Share:
13,230
Admin
Author by

Admin

Updated on June 11, 2022

Comments

  • Admin
    Admin almost 2 years

    When I run my spring boot application , it exits immediately (with exit code 0) with this:

     \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
      '  |____| .__|_| |_|_| |_\__, | / / / /
     =========|_|==============|___/=/_/_/_/
     :: Spring Boot ::        (v2.1.0.RELEASE)
    
    2018-11-27 14:08:31.219  INFO 94920 --- [  restartedMain] c.springbootsecurity.jwt.JwtApplication  : Starting JwtApplication on 1000810002637M.local with PID 94920 (/Users/723305/Documents/spring/springbootSecure/target/classes started by 723305 in /Users/723305/Documents/spring/springbootSecure)
    2018-11-27 14:08:31.222  INFO 94920 --- [  restartedMain] c.springbootsecurity.jwt.JwtApplication  : No active profile set, falling back to default profiles: default
    2018-11-27 14:08:31.252  INFO 94920 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
    2018-11-27 14:08:31.722  INFO 94920 --- [  restartedMain] o.s.b.d.a.OptionalLiveReloadServer       : LiveReload server is running on port 35729
    2018-11-27 14:08:31.743  INFO 94920 --- [  restartedMain] c.springbootsecurity.jwt.JwtApplication  : Started JwtApplication in 0.752 seconds (JVM running for 1.294)
    
    Process finished with exit code 0
    

    my pom.xml file:

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
    
        <groupId>com.springbootSecurity</groupId>
        <artifactId>jwt</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <packaging>jar</packaging>
    
        <name>jwt</name>
        <description>Demo project for Spring Boot</description>
    
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.1.0.RELEASE</version>
            <relativePath/> <!-- lookup parent from repository -->
        </parent>
    
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
            <java.version>1.8</java.version>
        </properties>
    
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-security</artifactId>
            </dependency>
    
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-devtools</artifactId>
                <scope>runtime</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.security</groupId>
                <artifactId>spring-security-test</artifactId>
                <scope>test</scope>
            </dependency>
        </dependencies>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
    
            </plugins>
        </build>        
    </project>
    
  • Admin
    Admin over 5 years
    <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>. even this doesn't work
  • bittu
    bittu over 5 years
    ok do you still get the same logs ? Any logs like "tomcat started on port 8080" not coming ?
  • bittu
    bittu over 5 years
    Very strange. Seems like web dependency is not added to your classpath. Can you just reimport all dependency of your module and restart the application.
  • bittu
    bittu over 5 years
    Executing maven clean install will reimport all dependency
  • Alex78191
    Alex78191 almost 4 years
    spring-boot-starter-web is needed
  • Alex78191
    Alex78191 almost 4 years
    you should add <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>
  • avdyk
    avdyk almost 4 years
    As I wrote: "event with the spring-boot-starter-web" ;-)
  • Kendall Trego
    Kendall Trego over 3 years
    I had the same problem in intellij, but instead fixed it by right clicking the project -> maven -> reload project after switching the dependencies as described
  • Nikolas
    Nikolas about 3 years
    I have spring-boot-started-web dependency, but it is still exit.
  • Rag
    Rag almost 3 years
    Above worked. I had to reimport the project (right click on project root folder -> Maven -> Reimport). It seems to be an issue with IntelliJ possibly detecting early on as standalone desktop project and later properly recognises as web project and initialises Tomcat (binds to the port and waits for connections).
  • Mark
    Mark almost 2 years
    I had this problem also, and I had the spring-boot-starter-web dependency. But I inadvertently excluded the spring-boot-starter-tomcat dependency that web normally brings in, and forgot to add a suitable replacement. My solution was to add spring-boot-starter-jetty.