SPring 启动服务之间的共享配置(在 git 中) [英] Shared Config(at git) between SPring Boot Services

查看:25
本文介绍了SPring 启动服务之间的共享配置(在 git 中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发 Spring Boot 服务.

I am developing spring boot services.

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

So lets say I have 3 Services A, B, C with dev and prod profiles each. Now I am keeping the configuration for these services at GIT and using config server to fetch the configuration.

因此,当我在 prod 模式下运行 A 服务时,会使用配置文件 A-prod.properties.

So when I run A service in prod mode, the config file A-prod.properties is getting used.

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

Now I want to keep some common configuration which will be used by all 3 Services say common-prod.properties. How should I do that?

我已经试过了:

配置服务器:

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

我的属性文件按以下顺序在 Git Repo 中:

My properties are file are in Git Repo in this order :

- 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

推荐答案

您可以将服务之间的所有共享属性放在 application-<profile>.properties 文件中.

You can put all shared properties between services in application-<profile>.properties file.

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

In your case, make application-prod.properties and application-dev.properties files and put these file on root folder or any folder that is searchable by config server.

您可以在 此处.

这篇关于SPring 启动服务之间的共享配置(在 git 中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆