我的第一个使用MySQL和JPA的Spring Boot应用程序立即关闭,我不知道原因。

2018-08-15 16:24:42.050  INFO 10960 --- [  restartedMain] com.classpath.SampleAppApplication       : Starting SampleAppApplication on LAPTOP-MAI0FJBD with PID 10960 (C:\Users\classpath\projects\sample-app\target\classes started by classpath in C:\Users\classpath\projects\sample-app)
2018-08-15 16:24:42.065  INFO 10960 --- [  restartedMain] com.classpath.SampleAppApplication       : No active profile set, falling back to default profiles: default
2018-08-15 16:24:42.160  INFO 10960 --- [  restartedMain] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@699320b1: startup date [Wed Aug 15 16:24:42 IST 2018]; root of context hierarchy
2018-08-15 16:24:43.978  INFO 10960 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2018-08-15 16:24:44.245  INFO 10960 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2018-08-15 16:24:44.291  INFO 10960 --- [  restartedMain] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2018-08-15 16:24:44.307  INFO 10960 --- [  restartedMain] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
    name: default
    ...]
2018-08-15 16:24:44.369  INFO 10960 --- [  restartedMain] org.hibernate.Version                    : HHH000412: Hibernate Core {5.2.17.Final}
2018-08-15 16:24:44.369  INFO 10960 --- [  restartedMain] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
2018-08-15 16:24:44.416  INFO 10960 --- [  restartedMain] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2018-08-15 16:24:44.526  INFO 10960 --- [  restartedMain] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2018-08-15 16:24:45.246  INFO 10960 --- [  restartedMain] o.h.t.schema.internal.SchemaCreatorImpl  : HHH000476: Executing import script 'org.hibernate.tool.schema.internal.exec.ScriptSourceInputNonExistentImpl@49cf4e94'
2018-08-15 16:24:45.262  INFO 10960 --- [  restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2018-08-15 16:24:46.058  INFO 10960 --- [  restartedMain] o.s.b.d.a.OptionalLiveReloadServer       : LiveReload server is running on port 35729
2018-08-15 16:24:46.089  INFO 10960 --- [  restartedMain] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2018-08-15 16:24:46.089  INFO 10960 --- [  restartedMain] o.s.j.e.a.AnnotationMBeanExporter        : Bean with name 'dataSource' has been autodetected for JMX exposure
2018-08-15 16:24:46.089  INFO 10960 --- [  restartedMain] o.s.j.e.a.AnnotationMBeanExporter        : Located MBean 'dataSource': registering with JMX server as MBean [com.zaxxer.hikari:name=dataSource,type=HikariDataSource]
2018-08-15 16:24:46.105  INFO 10960 --- [  restartedMain] com.classpath.SampleAppApplication       : Started SampleAppApplication in 4.437 seconds (JVM running for 4.942)
2018-08-15 16:24:46.121  INFO 10960 --- [       Thread-8] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@699320b1: startup date [Wed Aug 15 16:24:42 IST 2018]; root of context hierarchy
2018-08-15 16:24:46.121  INFO 10960 --- [       Thread-8] o.s.j.e.a.AnnotationMBeanExporter        : Unregistering JMX-exposed beans on shutdown
2018-08-15 16:24:46.121  INFO 10960 --- [       Thread-8] o.s.j.e.a.AnnotationMBeanExporter        : Unregistering JMX-exposed beans
2018-08-15 16:24:46.121  INFO 10960 --- [       Thread-8] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2018-08-15 16:24:46.121  INFO 10960 --- [       Thread-8] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown initiated...
2018-08-15 16:24:46.121  INFO 10960 --- [       Thread-8] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown completed.

Process finished with exit code 0


以下是pom.xml文件中添加的依赖项。
    
    http://maven.apache.org/xsd/maven-4.0.0.xsd“>
        4.0.0
        com.classpath
        示例应用
        0.0.1-快照
        罐

    <name>sample-app</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.4.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-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</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>
        </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-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>
        </plugins>
    </build>
</project>


我还在下面添加了SpringBoot注释的类

package com.classpath;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

    @SpringBootApplication
    public class SampleAppApplication {

        public static void main(String[] args) {
            SpringApplication.run(SampleAppApplication.class, args);
        }
    }


请让我知道我要去哪里哪里以及如何调试此问题。似乎Spring在这里发挥了太多的作用。

最佳答案

您的数据库依赖性如何?在pom.xml中配置嵌入式数据库(H2,HSQL或Derby)或其他关系数据库,例如oracle或mysql依赖项。

例:

   <dependency>
        <groupId>org.hsqldb</groupId>
        <artifactId>hsqldb</artifactId>
        <scope>runtime</scope>
    </dependency>

10-06 02:23