【发布时间】:2020-10-30 15:29:56
【问题描述】:
我正在尝试遵循本指南 https://spring.io/guides/gs/accessing-data-mysql/
但本指南适用于 maven,我正在尝试 gradle
得到这个错误
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
在 application.properties 我只有这些东西。
spring.datasource.url=jdbc:mysql://localhost:3306/db_example
spring.datasource.username=root
spring.datasource.password=root
spring.jpa.hibernate.ddl-auto=update
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
我尝试了 SO 上所有可能的东西。
我唯一的部门是这些
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
runtimeOnly 'mysql:mysql-connector-java'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
【问题讨论】:
-
spring.datasource.url未在您的属性文件中设置。假设您使用的是本地 mysql 数据库,可能应该将其设置为:localhost:3306/mydb -
@Ervin 我认为由于stackoverflow的格式而错过了它。我已经更新了这个问题。如果我遗漏了什么,您能告诉我吗?
-
您确定使用了这个 application.properties 文件吗?你在哪里定义了这个属性文件?
-
@Berthol 我也检查了那个问题,他们告诉我排除我不想做的
DataSourceAutoConfiguration.class。
标签: mysql spring spring-boot