Why does my Spring Boot application shuts down as soon as I run it?

Viewed 916

I used Spring Initializr to set up my Spring Application. The application exits without any error as soon as I run it. The console logs this:

2021-02-22 13:31:20.206  INFO 68562 --- [extShutdownHook] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2021-02-22 13:31:20.216  INFO 68562 --- [extShutdownHook] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown initiated...
2021-02-22 13:31:20.294  INFO 68562 --- [extShutdownHook] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown completed.

I tried changing the spring-boot-starter-parent version but that still doesn't seem to work. I tried rebuilding the project but that didn't work as well. Could you tell me what I'm doing wrong here? It doesn't even return any error. It just doesn't run on the server.

Here is my pom.xml:

    <?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.2</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.manjitmentor.sms</groupId>
    <artifactId>sms</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>sms</name>
    <description>Student Management System project by Java Full Stack Mentor Manjit Shakya.</description>
    <properties>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <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>
            <exclusions>
                <exclusion>
                    <groupId>logback-classic</groupId>
                    <artifactId>ch.qos.logback</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>log4j-over-slf4j</groupId>
                    <artifactId>org.slf4j</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.modelmapper/modelmapper -->
        <dependency>
            <groupId>org.modelmapper</groupId>
            <artifactId>modelmapper</artifactId>
            <version>2.3.9</version>
        </dependency>


        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <!--Logging-->

        <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.30</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/log4j/log4j -->
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

Here's my yml file:

server:
  port: 8080
  servlet:
    context-path: /sms
spring:
  application:
    name: sms
  datasource:
    url: jdbc:mysql://localhost:3306/SMS
    username: root
    password: idrunkh2o
    driver-class-name: com.mysql.cj.jdbc.Driver
    hikari:
      maximum-pool-size: 100
      minimum-idel: 50
  jpa:
    database-platfrom: org.hibernate.dialect.MySQL5InnoDBDialect
    generate-ddl: true
    show-sql: true
    hibernate:
      ddl-auto: update

COMPLETE LOG:

/Library/Java/JavaVirtualMachines/amazon-corretto-11.jdk/Contents/Home/bin/java -javaagent:/Applications/IntelliJ IDEA CE.app/Contents/lib/idea_rt.jar=56405:/Applications/IntelliJ IDEA CE.app/Contents/bin -Dfile.encoding=UTF-8 -classpath /Users/aakashthakur-work/Documents/F1SoftManjitShakyaTraining/sms/target/classes:/Users/aakashthakur-work/.m2/repository/org/springframework/boot/spring-boot-starter-data-jpa/2.4.2/spring-boot-starter-data-jpa-2.4.2.jar:/Users/aakashthakur-work/.m2/repository/org/springframework/boot/spring-boot-starter-aop/2.4.2/spring-boot-starter-aop-2.4.2.jar:/Users/aakashthakur-work/.m2/repository/org/springframework/spring-aop/5.3.3/spring-aop-5.3.3.jar:/Users/aakashthakur-work/.m2/repository/org/aspectj/aspectjweaver/1.9.6/aspectjweaver-1.9.6.jar:/Users/aakashthakur-work/.m2/repository/org/springframework/boot/spring-boot-starter-jdbc/2.4.2/spring-boot-starter-jdbc-2.4.2.jar:/Users/aakashthakur-work/.m2/repository/com/zaxxer/HikariCP/3.4.5/HikariCP-3.4.5.jar:/Users/aakashthakur-work/.m2/repository/org/springframework/spring-jdbc/5.3.3/spring-jdbc-5.3.3.jar:/Users/aakashthakur-work/.m2/repository/jakarta/transaction/jakarta.transaction-api/1.3.3/jakarta.transaction-api-1.3.3.jar:/Users/aakashthakur-work/.m2/repository/jakarta/persistence/jakarta.persistence-api/2.2.3/jakarta.persistence-api-2.2.3.jar:/Users/aakashthakur-work/.m2/repository/org/springframework/data/spring-data-jpa/2.4.3/spring-data-jpa-2.4.3.jar:/Users/aakashthakur-work/.m2/repository/org/springframework/data/spring-data-commons/2.4.3/spring-data-commons-2.4.3.jar:/Users/aakashthakur-work/.m2/repository/org/springframework/spring-orm/5.3.3/spring-orm-5.3.3.jar:/Users/aakashthakur-work/.m2/repository/org/springframework/spring-context/5.3.3/spring-context-5.3.3.jar:/Users/aakashthakur-work/.m2/repository/org/springframework/spring-tx/5.3.3/spring-tx-5.3.3.jar:/Users/aakashthakur-work/.m2/repository/org/springframework/spring-beans/5.3.3/spring-beans-5.3.3.jar:/Users/aakashthakur-work/.m2/repository/org/springframework/spring-aspects/5.3.3/spring-aspects-5.3.3.jar:/Users/aakashthakur-work/.m2/repository/org/springframework/boot/spring-boot-starter-web/2.4.2/spring-boot-starter-web-2.4.2.jar:/Users/aakashthakur-work/.m2/repository/org/springframework/boot/spring-boot-starter/2.4.2/spring-boot-starter-2.4.2.jar:/Users/aakashthakur-work/.m2/repository/org/springframework/boot/spring-boot-starter-logging/2.4.2/spring-boot-starter-logging-2.4.2.jar:/Users/aakashthakur-work/.m2/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar:/Users/aakashthakur-work/.m2/repository/ch/qos/logback/logback-core/1.2.3/logback-core-1.2.3.jar:/Users/aakashthakur-work/.m2/repository/org/apache/logging/log4j/log4j-to-slf4j/2.13.3/log4j-to-slf4j-2.13.3.jar:/Users/aakashthakur-work/.m2/repository/org/apache/logging/log4j/log4j-api/2.13.3/log4j-api-2.13.3.jar:/Users/aakashthakur-work/.m2/repository/org/slf4j/jul-to-slf4j/1.7.30/jul-to-slf4j-1.7.30.jar:/Users/aakashthakur-work/.m2/repository/org/yaml/snakeyaml/1.27/snakeyaml-1.27.jar:/Users/aakashthakur-work/.m2/repository/org/springframework/boot/spring-boot-starter-json/2.4.2/spring-boot-starter-json-2.4.2.jar:/Users/aakashthakur-work/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.11.4/jackson-databind-2.11.4.jar:/Users/aakashthakur-work/.m2/repository/com/fasterxml/jackson/core/jackson-annotations/2.11.4/jackson-annotations-2.11.4.jar:/Users/aakashthakur-work/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.11.4/jackson-core-2.11.4.jar:/Users/aakashthakur-work/.m2/repository/com/fasterxml/jackson/datatype/jackson-datatype-jdk8/2.11.4/jackson-datatype-jdk8-2.11.4.jar:/Users/aakashthakur-work/.m2/repository/com/fasterxml/jackson/datatype/jackson-datatype-jsr310/2.11.4/jackson-datatype-jsr310-2.11.4.jar:/Users/aakashthakur-work/.m2/repository/com/fasterxml/jackson/module/jackson-module-parameter-names/2.11.4/jackson-module-parameter-names-2.11.4.jar:/Users/aakashthakur-work/.m2/repository/org/springframework/spring-web/5.3.3/spring-web-5.3.3.jar:/Users/aakashthakur-work/.m2/repository/org/springframework/spring-webmvc/5.3.3/spring-webmvc-5.3.3.jar:/Users/aakashthakur-work/.m2/repository/org/springframework/spring-expression/5.3.3/spring-expression-5.3.3.jar:/Users/aakashthakur-work/.m2/repository/org/modelmapper/modelmapper/2.3.9/modelmapper-2.3.9.jar:/Users/aakashthakur-work/.m2/repository/org/springframework/boot/spring-boot-devtools/2.4.2/spring-boot-devtools-2.4.2.jar:/Users/aakashthakur-work/.m2/repository/org/springframework/boot/spring-boot/2.4.2/spring-boot-2.4.2.jar:/Users/aakashthakur-work/.m2/repository/org/springframework/boot/spring-boot-autoconfigure/2.4.2/spring-boot-autoconfigure-2.4.2.jar:/Users/aakashthakur-work/.m2/repository/mysql/mysql-connector-java/8.0.22/mysql-connector-java-8.0.22.jar:/Users/aakashthakur-work/.m2/repository/org/projectlombok/lombok/1.18.16/lombok-1.18.16.jar:/Users/aakashthakur-work/.m2/repository/jakarta/annotation/jakarta.annotation-api/1.3.5/jakarta.annotation-api-1.3.5.jar:/Users/aakashthakur-work/.m2/repository/jakarta/xml/bind/jakarta.xml.bind-api/2.3.3/jakarta.xml.bind-api-2.3.3.jar:/Users/aakashthakur-work/.m2/repository/jakarta/activation/jakarta.activation-api/1.2.2/jakarta.activation-api-1.2.2.jar:/Users/aakashthakur-work/.m2/repository/org/springframework/spring-core/5.3.3/spring-core-5.3.3.jar:/Users/aakashthakur-work/.m2/repository/org/springframework/spring-jcl/5.3.3/spring-jcl-5.3.3.jar:/Users/aakashthakur-work/.m2/repository/org/slf4j/slf4j-api/1.7.30/slf4j-api-1.7.30.jar:/Users/aakashthakur-work/.m2/repository/log4j/log4j/1.2.17/log4j-1.2.17.jar:/Users/aakashthakur-work/.m2/repository/org/hibernate/hibernate-core/5.4.27.Final/hibernate-core-5.4.27.Final.jar:/Users/aakashthakur-work/.m2/repository/org/jboss/logging/jboss-logging/3.4.1.Final/jboss-logging-3.4.1.Final.jar:/Users/aakashthakur-work/.m2/repository/javax/persistence/javax.persistence-api/2.2/javax.persistence-api-2.2.jar:/Users/aakashthakur-work/.m2/repository/org/javassist/javassist/3.27.0-GA/javassist-3.27.0-GA.jar:/Users/aakashthakur-work/.m2/repository/net/bytebuddy/byte-buddy/1.10.19/byte-buddy-1.10.19.jar:/Users/aakashthakur-work/.m2/repository/antlr/antlr/2.7.7/antlr-2.7.7.jar:/Users/aakashthakur-work/.m2/repository/org/jboss/spec/javax/transaction/jboss-transaction-api_1.2_spec/1.1.1.Final/jboss-transaction-api_1.2_spec-1.1.1.Final.jar:/Users/aakashthakur-work/.m2/repository/org/jboss/jandex/2.1.3.Final/jandex-2.1.3.Final.jar:/Users/aakashthakur-work/.m2/repository/com/fasterxml/classmate/1.5.1/classmate-1.5.1.jar:/Users/aakashthakur-work/.m2/repository/javax/activation/javax.activation-api/1.2.0/javax.activation-api-1.2.0.jar:/Users/aakashthakur-work/.m2/repository/org/dom4j/dom4j/2.1.3/dom4j-2.1.3.jar:/Users/aakashthakur-work/.m2/repository/org/hibernate/common/hibernate-commons-annotations/5.1.2.Final/hibernate-commons-annotations-5.1.2.Final.jar:/Users/aakashthakur-work/.m2/repository/javax/xml/bind/jaxb-api/2.3.1/jaxb-api-2.3.1.jar:/Users/aakashthakur-work/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.3.3/jaxb-runtime-2.3.3.jar:/Users/aakashthakur-work/.m2/repository/org/glassfish/jaxb/txw2/2.3.3/txw2-2.3.3.jar:/Users/aakashthakur-work/.m2/repository/com/sun/istack/istack-commons-runtime/3.0.11/istack-commons-runtime-3.0.11.jar:/Users/aakashthakur-work/.m2/repository/com/sun/activation/jakarta.activation/1.2.2/jakarta.activation-1.2.2.jar:/Users/aakashthakur-work/.m2/repository/org/hibernate/hibernate-entitymanager/5.4.27.Final/hibernate-entitymanager-5.4.27.Final.jar com.manjitmentor.sms.SmsApplication

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.4.2)

2021-02-22 15:03:29.750  INFO 74414 --- [  restartedMain] com.manjitmentor.sms.SmsApplication      : Starting SmsApplication using Java 11.0.9.1 on Aakashs-MacBook-Air.local with PID 74414 (/Users/aakashthakur-work/Documents/F1SoftManjitShakyaTraining/sms/target/classes started by aakashthakur-work in /Users/aakashthakur-work/Documents/F1SoftManjitShakyaTraining/sms)
2021-02-22 15:03:29.757  INFO 74414 --- [  restartedMain] com.manjitmentor.sms.SmsApplication      : No active profile set, falling back to default profiles: default
2021-02-22 15:03:29.949  INFO 74414 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2021-02-22 15:03:31.312  INFO 74414 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2021-02-22 15:03:31.431  INFO 74414 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 97 ms. Found 1 JPA repository interfaces.
2021-02-22 15:03:32.292  INFO 74414 --- [  restartedMain] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]
2021-02-22 15:03:32.448  INFO 74414 --- [  restartedMain] org.hibernate.Version                    : HHH000412: Hibernate ORM core version 5.4.27.Final
2021-02-22 15:03:32.841  INFO 74414 --- [  restartedMain] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2021-02-22 15:03:33.179  INFO 74414 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2021-02-22 15:03:33.817  INFO 74414 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2021-02-22 15:03:33.930  INFO 74414 --- [  restartedMain] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.MySQL8Dialect
2021-02-22 15:03:35.897  INFO 74414 --- [  restartedMain] o.h.e.t.j.p.i.JtaPlatformInitiator       : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2021-02-22 15:03:35.922  INFO 74414 --- [  restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2021-02-22 15:03:35.959  INFO 74414 --- [  restartedMain] o.s.b.d.a.OptionalLiveReloadServer       : LiveReload server is running on port 35729
2021-02-22 15:03:36.963  INFO 74414 --- [  restartedMain] com.manjitmentor.sms.SmsApplication      : Started SmsApplication in 8.539 seconds (JVM running for 10.162)
2021-02-22 15:03:36.968  INFO 74414 --- [  restartedMain] com.manjitmentor.sms.SmsApplication      : 

,d88~~\      e    e      ,d88~~\ 
8888        d8b  d8b     8888    
`Y88b      d888bdY88b    `Y88b   
 `Y88b,   / Y88Y Y888b    `Y88b, 
   8888  /   YY   Y888b     8888 
\__88P' /          Y888b \__88P' 
                                 
2021-02-22 15:03:36.975  INFO 74414 --- [extShutdownHook] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2021-02-22 15:03:36.982  INFO 74414 --- [extShutdownHook] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown initiated...
2021-02-22 15:03:37.037  INFO 74414 --- [extShutdownHook] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown completed.

Process finished with exit code 0
2 Answers

I think that this is causing trouble and you should remove it

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

You have this one that has the Tomcat already embedded

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

So a brief overview on why you faced the issue:

You tried to use an external tomcat and specified to your application that you will provide it to it by the runtime <scope>provided</scope> check it here. But the application already has it embedded in it, and spring-boot by default creates a jar file, the tomcat needs a war file. In addition, the tomcat server won't launch your main method, you need to start your application as a normal spring app.

To use an external tomcat server follow these steps:

  1. Set the packing to generate war

    <packaging>war</packaging>

  2. Add the external tomcat dependency

        <dependency>
            <groupid>org.springframework.boot</groupid>
            <artifactid>spring-boot-starter-tomcat</artifactid>
            <scope>provided</scope>
        </dependency>
  1. Exclude the embedded tomcat from the spring-boot-starter-web
<dependency>
<groupid>org.springframework.boot</groupid>
<artifactid>spring-boot-starter-web</artifactid>
            <exclusions>
                <exclusion>
                    <groupid>org.springframework.boot</groupid>
                    <artifactid>spring-boot-starter-tomcat</artifactid>
                </exclusion>
            </exclusions>
</dependency>

And make a bunch of configurations to make it start as a Spring app and add the external configuration of your spring boot app on tomcat.

Check this article here I think it will complete the whole idea. link

I used to have a similar problem. I don't precisely know how It works, I am a beginner, as you might have guessed.

Here's how I solved mine.

  1. Right click the project and update Maven project.
  2. Then close your Builder and restart your device.
  3. Run the project again.

Please Keep me posted on how it works out.

Related