我有嘗試連接到本地資料庫的 Spring Boot 應用程式。我可以將該檔案作為常規 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 依賴項,并且 postgresql-42.2.19.jar 在那里。
在我的 application-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建議的
uj5u.com熱心網友回復:
您擁有的資料庫屬性application-default.yml只有在您使用“默認”彈簧組態檔時才會被激活。
因此,要么使用“默認”彈簧組態檔(不是 maven 組態檔),要么將默認使用的屬性移動到application.yml無論您是否使用任何組態檔。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/433945.html
