我正在尝试遵循这个指南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我试过了所有可能的东西。
我唯一的警员就是这些
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'
}
}发布于 2021-02-09 16:13:46
这是一个老问题,但对于遇到这个问题的任何其他人来说,如果你碰巧正在使用IntelliJ (就像OP基于他/她的评论所做的那样),请确保我们深爱的集成开发环境能够识别你的应用程序.properties/application.yml,方法是转到File -> Project Structure -> Modules,然后选择你的resources文件并点击Mark as:头文件中的“资源”(基于IntelliJ社区版2019.1)。还要记住,毫无疑问,IDE肯定会通知您,通过重新导入任何Maven更改,您将需要再次执行此过程。
发布于 2020-07-10 09:45:07
或者,您必须通过将以下行添加到文件application.properties来阻止Spring boot自动配置数据源。
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
发布于 2020-07-10 11:55:27
检查目标类路径目录。如果application.properties文件不存在,则删除目标并重新构建。
https://stackoverflow.com/questions/62824978
复制相似问题