我有Spring应用程序,我试图连接到我的本地数据库。我可以将该文件作为常规Java文件运行,并且它连接到数据库时没有任何错误。但是,当我运行mvn clean spring-boot:run时,它会输出以下输出。
***************************
APPLICATION FAILED TO START
***************************
Description:
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在我的pom.xml里
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>我检查了Maven依赖项,PostgreSQL42.2.19.jar也在其中。
在我的应用程序中-default.yml
spring:
datasource:
driverClassName: org.postgresql.Driver
url: jdbc:postgresql://localhost:5432/pharmacy
username: ****
password: ****
platform: postgresql
initialize: false
continue-on-error: false这是由https://www.baeldung.com/spring-boot-failed-to-configure-data-source建议的
发布于 2022-02-25 04:55:27
application-default.yml中的数据库属性只有在使用“默认”spring配置文件时才会被激活。
因此,要么使用“默认”spring配置文件(而不是maven配置文件),要么将属性移动到application.yml,不管您是否使用任何配置文件,默认情况下都将使用该属性。
https://stackoverflow.com/questions/71245518
复制相似问题