Spring Cloud Config Server 跨应用程序共享属性

标签 spring properties spring-cloud spring-cloud-config

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

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

目前它看起来像这样:-

Web1
- 数据库
- jms

消息1
- 数据库
- jms

在这种情况下,两个部署的应用程序共享相同的连接,并且这些连接会因环境(实验室、prf、prd 等)而变化。如何使用 Spring Configuration Server 实现相同的功能,其中每个可部署应用程序都有应用程序配置?

Application.yml
Web1.yml
Web1-dev.yml
消息1.yml
Messaging1-dev.yml

如果某个环境的连接属性发生更改,我需要对每个可部署的应用程序配置进行更改,而不是只更改一次。

目前有没有办法实现这一目标?我只是错过了一个简单的点吗?

最佳答案

我在这里找到了可行的解决方案 https://cloud.spring.io/spring-cloud-config/single/spring-cloud-config.html ,段落“2.1.5 与所有应用程序共享配置”。它说:

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.

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

关于Spring Cloud Config Server 跨应用程序共享属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29781981/

相关文章:

Swift:访问结构字典中的属性

java - 是否可以在没有功能区的情况下使用@FeignClient?

java - 无法在 Windows 7 x64 上使用 gradle 构建 spring 框架

java - 使用 Spring Autowired 注解时的 Nullpoint

java - Spring Boot 测试不使用 jmx 属性

python属性和继承

javascript - Javascript 中的服务器代码

spring-boot - spring 库是否有 EOL(生命周期结束)和 EOVS(供应商支持结束)日期?

spring-boot - Spring boot admin 列出 kubernetes 内部 url。无法导航到应用程序页面

java - 使用 Java 和 Spring、消息传递或 RMI 进行分布式计算?