【问题标题】:SpringBoot complementary configuration file in system directory系统目录下的Spring Boot补充配置文件
【发布时间】:2020-05-29 02:20:09
【问题描述】:

我需要一些帮助来使用另一个 .yml 文件来补充应用程序中的原始文件。然后我有一个由我(dev)填写的文件,但是我们的客户应该插入一些配置(作为数据库信息)。

应用程序中的一个(application.yml)具有通用配置,路径 C:\Users\Public\ datasource.yml 上的另一个具有:

spring:
  datasource:
    platform: postgres
    driverClassName: org.postgresql.Driver
    url: jdbc:postgresql://localhost:5432/mydb
    username: foo
    password: bar

以前有人做过吗?

【问题讨论】:

    标签: spring spring-boot datasource external spring-properties


    【解决方案1】:

    在您的主配置类中配置以下注解

    @PropertySource("classpath:datasource.yml")
    

    【讨论】:

    • 我收到错误,因为对于项目目录之外的文件(例如:C:\Users\Public),扩展名必须是 .properties 而不是 yml。
    猜你喜欢
    • 2019-02-22
    • 2018-08-12
    • 2019-02-21
    • 1970-01-01
    • 1970-01-01
    • 2020-05-07
    • 2016-08-22
    • 2011-09-08
    • 2011-03-21
    相关资源
    最近更新 更多