【问题标题】:Shared Config(at git) between SPring Boot ServicesSPring Boot Services 之间的共享配置(在 git 上)
【发布时间】:2018-01-11 22:43:08
【问题描述】:

我正在开发 Spring Boot 服务。

假设我有 3 个服务 A、B、C,每个服务都有 dev 和 prod 配置文件。现在我将这些服务的配置保存在 GIT 并使用配置服务器来获取配置。

所以当我在 prod 模式下运行 A 服务时,配置文件 A-prod.properties 正在被使用。

现在我想保留一些通用配置,所有 3 个服务都将使用它们,比如 common-prod.properties。我该怎么做?

我试过这个:

配置服务器:

spring:
  cloud:
    config:
      server:
        git:
          uri: http://gitPaath/Configs.git
          username: <username>
          password: <pass>
          cloneOnStart: true
          searchPaths: "{common}"

我的属性是文件按此顺序在 Git Repo 中:

- A-prod.properties
- A-dev.properties
- B-prod.properties
- A-dev.properties
- C-prod.properties
- C-dev.properties
- common
   - common-prod.propeties
   - common-dev.properties

【问题讨论】:

  • 你能解决这个问题吗,如果可以,请分享解决方案
  • 解决方案是下面公认的答案。简单创建应用程序-.properties 文件

标签: spring-boot spring-boot-configuration


【解决方案1】:

您可以将服务之间的所有共享属性放在application-&lt;profile&gt;.properties 文件中。

在您的情况下,制作 application-prod.propertiesapplication-dev.properties 文件并将这些文件放在根文件夹或配置服务器可搜索的任何文件夹中。

您可以在here 的“与所有应用程序共享配置”部分找到更多详细信息。

【讨论】:

    猜你喜欢
    • 2020-02-06
    • 1970-01-01
    • 2013-07-03
    • 2016-06-15
    • 2017-11-08
    • 1970-01-01
    • 2023-04-10
    • 2016-07-31
    • 2018-05-08
    相关资源
    最近更新 更多