试图按照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 classAction: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=createspring.datasource.url=jdbc:mysql://localhost:3306/db_currencyspring.datasource.username=springuserspring.datasource.password=ThePassword数据库创建遵循以下指南:mysql> create database db_example; -- Create the new databasemysql> 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.8targetCompatibility = 1.8dependencies { 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')}
1 回答
开心每一天1111
TA贡献1836条经验 获得超13个赞
通过研究,这个问题有多种答案适用于其他人,在我的情况下,将其添加到 application.properties 文件有效:
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQL94Dialect
添加回答
举报
0/150
提交
取消