首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Gradle项目--未能配置datasource‘’url‘属性,也无法配置任何嵌入式数据源

Gradle项目--未能配置datasource‘’url‘属性,也无法配置任何嵌入式数据源
EN

Stack Overflow用户
提问于 2018-10-11 02:30:47
回答 1查看 3.8K关注 0票数 3

尝试遵循https://spring.io/guides/gs/accessing-data-mysql/中的指南,但是当我启动java应用程序时,它显示了以下错误:

代码语言:javascript
复制
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:

代码语言:javascript
复制
spring.jpa.hibernate.ddl-auto=create
spring.datasource.url=jdbc:mysql://localhost:3306/db_currency
spring.datasource.username=springuser
spring.datasource.password=ThePassword

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

代码语言:javascript
复制
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是:

代码语言:javascript
复制
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')
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-02-13 12:44:46

通过研究,这个问题有多个答案适用于其他人,在我的例子中,将其添加到application.properties文件中是有效的:

代码语言:javascript
复制
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQL94Dialect
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52751287

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档