Maven 无法找到“url”;未指定属性且未嵌入
我有 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
I have Spring Boot application that I try to connect to my local database. I can run the file as a regular Java file and it connects to the database with no error. However, when I run mvn clean spring-boot:run
it prints the following output.
***************************
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
In my pom.xml I have
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
I checked the Maven dependencies and postgresql-42.2.19.jar is in there.
In my application-default.yml I have as
spring:
datasource:
driverClassName: org.postgresql.Driver
url: jdbc:postgresql://localhost:5432/pharmacy
username: ****
password: ****
platform: postgresql
initialize: false
continue-on-error: false
This is suggested by https://www.baeldung.com/spring-boot-failed-to-configure-data-source
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在
application-default.yml
中有数据库属性,只有当您使用“默认”spring 配置文件时才会激活该属性。因此,要么使用“默认”spring 配置文件(不是 maven 配置文件),要么将属性移动到
application.yml
,无论您是否使用任何配置文件,默认情况下都会使用它。You are having database properties in
application-default.yml
which only will be activated when you use "default" spring profile.So, either use "default" spring profile (not maven profile) or move the properties to
application.yml
which will be used by default whether you use any profiles or not.