【问题标题】:Spring boot data jpa APPLICATION FAILED TO STARTSpring Boot 数据 jpa 应用程序启动失败
【发布时间】:2019-02-20 19:43:03
【问题描述】:

我从 https://spring.io/guides/gs/accessing-data-jpa/#initial 和 git clone 项目学习 JPA

我按照这个例子做了一个java文件,但它仍然是错误的。 我该如何解决?

------------

------------

启动 ApplicationContext 时出错。要显示条件报告,请在启用“调试”的情况下重新运行您的应用程序。 2018-06-09 16:41:37.706 错误 18872 --- [主要] o.s.b.d.LoggingFailureAnalysisReporter:


应用程序启动失败


说明:

配置数据源失败:未指定“url”属性,无法配置嵌入式数据源。

原因:无法确定合适的驱动程序类

行动:

考虑以下几点: 如果您想要一个嵌入式数据库(H2、HSQL 或 Derby),请将其放在类路径中。 如果您有要从特定配置文件加载的数据库设置,您可能需要激活它(当前没有配置文件处于活动状态)。

---------

---------

pom.xml file

http://maven.apache.org/maven-v4_0_0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 4.0.0

<groupId>org.springframework</groupId>
<artifactId>gs-accessing-data-jpa</artifactId>
<version>0.1.0</version>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.2.RELEASE</version>
</parent>

<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>com.h2database</groupId>
        <artifactId>h2</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

<repositories>
    <repository>
        <id>spring-releases</id>
        <name>Spring Releases</name>
        <url>https://repo.spring.io/libs-release</url>
    </repository>
    <repository>
        <id>org.jboss.repository.releases</id>
        <name>JBoss Maven Release Repository</name>
        <url>https://repository.jboss.org/nexus/content/repositories/releases</url>
    </repository>
</repositories>

<pluginRepositories>
    <pluginRepository>
        <id>spring-releases</id>
        <name>Spring Releases</name>
        <url>https://repo.spring.io/libs-release</url>
    </pluginRepository>
</pluginRepositories>

【问题讨论】:

    标签: spring-data-jpa


    【解决方案1】:

    您在pom.xml 中使用了spring-boot-starter-data-jpa。但我猜,appllication.properties 文件中没有调整数据源。如果你想使用数据库连接,application.properties 文件应该包含这样的配置:

    spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
    spring.datasource.username=mysqluser
    spring.datasource.password=mysqlpass
    spring.datasource.url=jdbc:mysql://localhost:8080/myDb?createDatabaseIfNotExist=true
    

    否则如果不使用jpa,从pom.xml中移除spring-boot-starter-data-jpa依赖:

    删除:

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

    然后再次尝试运行应用程序。

    【讨论】:

      猜你喜欢
      • 2017-05-12
      • 2019-02-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-23
      • 2021-06-06
      • 1970-01-01
      • 2019-09-07
      相关资源
      最近更新 更多