Spring Cloud Config Server跨应用程序共享属性 [英] Spring Cloud Config Server Shared Properties Across Applications

查看:196
本文介绍了Spring Cloud Config Server跨应用程序共享属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有许多可部署的应用程序,它们以分布式方式工作以解决业务问题.当前,我们正在使用许多属性配置文件,以根据系统环境变量提供每个环境不断变化的配置.所有这些可部署的应用程序共享数据库和消息传递的通用配置.当前,这是通过从类路径中获取属性文件并让两个已部署的应用程序为包含属性文件的每个连接(db,jms)共享一个公共jar来实现的.

I currently have a number of deployable applications that work in a distributed fashion to solve a business problem. We are currently using a number of property configuration files to provide changing configuration per environment based off a system environment variable. All these deployable application share common configuration for database and messaging. This is currently achieved by picking up property files from the class path and having both deployed apps share a common jar for each connection (db, jms) containing property files.

如果可以的话,我希望开始使用Spring Config Server来外部化此配置.我有一个关于如何共享此通用配置的问题.

I am looking to start using Spring Config Server to externalize this configuration if possible. I have a question about how to share this common config.

当前看起来像这样:-

Web1
-数据库
-jms

Web1
- database
- jms

消息传递1
-数据库
-jms

Messaging1
- database
- jms

在这种情况下,两个已部署的应用程序共享相同的连接,并且这些连接随环境(实验室,PRF,PRD等)而变化.我如何在Spring Configuration Server上实现相同的目标,在Spring Configuration Server中为每个可部署的应用程序配置应用程序配置?

In this situation both deployed apps share the same connections and these connections change per environment (lab, prf, prd, etc). How can I achieve the same with the Spring Configuration Server where I have app config for each deployable app?

Application.yml
Web1.yml
Web1-dev.yml
Messaging1.yml
Messaging1-dev.yml

Application.yml
Web1.yml
Web1-dev.yml
Messaging1.yml
Messaging1-dev.yml

如果针对环境更改了连接属性,则需要对每个可部署的应用程序配置进行更改,而不是仅进行一次更改.

If a connection property changed for an environment I would need to make the change to each deployable app configuration rather than making it just once.

目前是否有实现此目标的方法?我只是想念一个简单的观点吗?

Is there currently anyway to achieve this? Am I just missing a simple point?

推荐答案

我在这里找到了可行的解决方案

I found working solution here https://cloud.spring.io/spring-cloud-config/single/spring-cloud-config.html, paragraph "2.1.5 Sharing Configuration With All Applications". It says:

使用基于文件(例如git,svn和本机)的存储库,资源 应用程序中带有文件名的文件*在所有客户端之间共享 应用程序(例如application.properties,application.yml, application-*.properties等).您可以将资源与这些文件一起使用 名称以配置全局默认值并被它们覆盖 特定于应用程序的文件.

With file-based (i.e. git, svn and native) repositories, resources with file names in application* are shared between all client applications (so application.properties, application.yml, application-*.properties etc.). You can use resources with these file names to configure global defaults and have them overridden by application-specific files as necessary.

您应该在配置存储库的顶层(如果它是基于git或svn的)创建application.properties或application.yml.不要忘记提交更改.

You should create application.properties or application.yml at the top level of configuration repository (if it is git or svn based). Don't forget to commit the changes.

这篇关于Spring Cloud Config Server跨应用程序共享属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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