【问题标题】:Gradle project --Failed to configure a DataSource'url' attribute is not specified and no embedded datasource could be configuredGradle 项目 -- 未能配置 DataSource 'url' 属性未指定且无法配置嵌入式数据源
【发布时间】:2019-03-16 00:26:12
【问题描述】:

尝试按照 https://spring.io/guides/gs/accessing-data-mysql/ 中的指南进行操作,但是当我启动我的 java 应用程序时,它显示错误:

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class


Action:

Consider the following:
    If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
    If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

这是我的 application.property:

spring.jpa.hibernate.ddl-auto=create
spring.datasource.url=jdbc:mysql://localhost:3306/db_currency
spring.datasource.username=springuser
spring.datasource.password=ThePassword

数据库创建遵循以下指南:

mysql> create database db_example; -- Create the new database
mysql> create user 'springuser'@'localhost' identified by 'ThePassword'; 
mysql> grant all on db_example.* to 'springuser'@'localhost';

而我的 build.gradle 是:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.5.RELEASE")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

bootJar {
    baseName = 'gs-accessing-data-mysql'
    version =  '0.1.0'
}

repositories {
    mavenCentral()
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web")

    // JPA Data (We are going to use Repositories, Entities, Hibernate, etc...)
    compile 'org.springframework.boot:spring-boot-starter-data-jpa'

    // Use MySQL Connector-J
    compile 'mysql:mysql-connector-java'

    testCompile('org.springframework.boot:spring-boot-starter-test')
}

【问题讨论】:

  • 放置配置数据的文件应命名为 application.properties 而不是 applicaiton.property
  • 它被命名为“application.properties”
  • 其实我想知道这是否是 Intellij Idea 的错误。当我一次打开我的项目时发生了这个错误。然后我克隆我的代码并在另一个文件夹中构建我的项目,它似乎工作。我觉得 Intellij Idea 在 Mac 上的 gradle 效果不太好

标签: java mysql spring-boot gradle


【解决方案1】:

通过研究,这个问题有多种答案适用于其他人,在我的情况下,将其添加到 application.properties 文件中是可行的:

spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQL94Dialect

【讨论】:

    猜你喜欢
    • 2020-05-31
    • 2020-12-17
    • 2022-07-21
    • 2021-05-14
    • 2019-03-25
    • 2019-08-24
    • 2021-03-18
    • 2019-08-07
    • 2019-10-30
    相关资源
    最近更新 更多