首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring Boot DataSource:未指定“url”属性

Spring Boot DataSource:未指定“url”属性
EN

Stack Overflow用户
提问于 2020-07-10 07:02:20
回答 6查看 5.3K关注 0票数 5

我正在尝试遵循这个指南https://spring.io/guides/gs/accessing-data-mysql/

但是这本指南是给maven的,我正在尝试gradle

并得到这个错误

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

在application.properties中,我只有这些东西。

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

我试过了所有可能的东西。

我唯一的警员就是这些

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

回答 6

Stack Overflow用户

发布于 2021-02-09 16:13:46

这是一个老问题,但对于遇到这个问题的任何其他人来说,如果你碰巧正在使用IntelliJ (就像OP基于他/她的评论所做的那样),请确保我们深爱的集成开发环境能够识别你的应用程序.properties/application.yml,方法是转到File -> Project Structure -> Modules,然后选择你的resources文件并点击Mark as:头文件中的“资源”(基于IntelliJ社区版2019.1)。还要记住,毫无疑问,IDE肯定会通知您,通过重新导入任何Maven更改,您将需要再次执行此过程。

票数 1
EN

Stack Overflow用户

发布于 2020-07-10 09:45:07

或者,您必须通过将以下行添加到文件application.properties来阻止Spring boot自动配置数据源。

spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration

票数 0
EN

Stack Overflow用户

发布于 2020-07-10 11:55:27

检查目标类路径目录。如果application.properties文件不存在,则删除目标并重新构建。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62824978

复制
相关文章

相似问题

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