首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未指定Maven无法找到“url”属性,也没有嵌入

未指定Maven无法找到“url”属性,也没有嵌入
EN

Stack Overflow用户
提问于 2022-02-24 00:09:24
回答 1查看 79关注 0票数 1

我有Spring应用程序,我试图连接到我的本地数据库。我可以将该文件作为常规Java文件运行,并且它连接到数据库时没有任何错误。但是,当我运行mvn clean spring-boot:run时,它会输出以下输出。

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

代码语言:javascript
复制
<dependency>
    <groupId>org.postgresql</groupId>
    <artifactId>postgresql</artifactId>
    <scope>runtime</scope>
</dependency>

我检查了Maven依赖项,PostgreSQL42.2.19.jar也在其中。

在我的应用程序中-default.yml

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-02-25 04:55:27

application-default.yml中的数据库属性只有在使用“默认”spring配置文件时才会被激活。

因此,要么使用“默认”spring配置文件(而不是maven配置文件),要么将属性移动到application.yml,不管您是否使用任何配置文件,默认情况下都将使用该属性。

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

https://stackoverflow.com/questions/71245518

复制
相关文章

相似问题

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