Why does Spring Boot web app close immediately after starting?

后端 未结 10 2358
南笙
南笙 2021-02-18 15:57

Using STS, if I import the \"Rest Service\" Getting Started project using the latest Spring Boot and choose \"Run As Spring Boot App\", it starts up, t

相关标签:
10条回答
  • 2021-02-18 16:25

    I found the reason for this to happen. Mine was that I did not include any library which brings in the tomcat runtime with it. I included the spring-web dependency and spring-boot-starter-data-jpa(shown below) but none of these packages will bring the tomcat runtime for this app to run. So, it was auto shutdown.

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

    The solution was to change the spring-web to spring-boot-starter-web(shown below). This library brings in the tomcat library and my app started.

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    
    0 讨论(0)
  • 2021-02-18 16:31

    I just had the same problem and spent a while searching for a solution. I know the question is a few years old now but this might save someone else's time in future.

    I got this warning message when I ran mvn clean install:

    [WARNING] error reading /Users/fotouhm/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/8.5.16/tomcat-embed-core-8.5.16.jar; zip file is empty
    

    Turns out for some reason this file was corrupted. Just go to the link below and replace it.

    http://central.maven.org/maven2/org/apache/tomcat/embed/tomcat-embed-core/8.5.16/tomcat-embed-core-8.5.16.jar

    0 讨论(0)
  • 2021-02-18 16:34

    Check the mvn log when you execute package phase ,and make sure that the tomcat-embed-core jar is assigned into you app jar.

    0 讨论(0)
  • 2021-02-18 16:35

    Just add

     spring.main.web-environment=true
    

    in application.properties and restart.

    0 讨论(0)
  • 2021-02-18 16:41

    All the answers suggested that tomcat is missing from it. in my case it was tagged in my pom with <scope>provided</scope> which I think i did it as i would need to run my application on another App server later. So yes that was the issue for me just another version of the same problem.

    0 讨论(0)
  • 2021-02-18 16:44

    I had the same issue where my spring-boot app shuts down immediately without any trace of tomcat being started up although I had the dependency <artifactId>spring-boot-starter-web</artifactId> included in my pom.xml. This indicates that spring-boot isn't recognizing my app as a web application.

    Tried cleaning up and packaging my app again using mvn clean install utilities to verify if tomcat libraries are getting packaged into my app binary/deployable. Found the following issue (look for line starting with '[WARNING]'):

    [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ exam-launcher ---
    [INFO] Changes detected - recompiling the module!
    [INFO] Compiling 2 source files to C:\XXXXX\XXXXXX\XXXX_Workspace\my-app\target\classes
    [WARNING] error reading c:\.m2\org\apache\tomcat\embed\tomcat-embed-core\8.5.14\tomcat-embed-core-8.5.14.jar; invalid LOC header (bad signature)
    [INFO] 
    [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ exam-launcher ---
    [INFO] Using 'UTF-8' encoding to copy filtered resources.
    [INFO] skip non existing resourceDirectory C:\Chaithu\Work_Related\Eclipse_Neon_Workspace\exam-portal-server\src\test\resources
    

    The tomcat library I had on my local repo got corrupted (for some unknown reasons) because of which it wasn't getting included in the maven package. Deleted the corresponding folder from my local maven repo and let maven download it freshly. And it works like a charm now !!

    0 讨论(0)
提交回复
热议问题