Zir*_*kos 8 java spring spring-boot spring-cloud spring-cloud-config
我正在尝试迁移稳定的app服务器,以便从Spring Cloud Config服务器获取配置.每个应用程序{my-app}.yml在配置服务器上都有一个文件,我们可以使用配置文件(在名为{my-app}-{profile}.yml或使用多配置文件的YAML文档的文件中)为每个应用程序的每个环境配置不同的配置,我们甚至可以在另一个应用程序中包含一个配置文件spring.profiles.include用于提供一些继承 - 到目前为止,这么好.
但是,我们只能包含来自同一个应用程序的配置文件,并且我们有几个应用程序从同一配置服务器配置,每个环境共享大量配置 - 例如,他们几乎都使用相同的DataSource配置连接到同一个数据库同样用于消息传递,缓存等.这是很多重复的配置和许多需要更改的地方 - 正是Spring Cloud Config应该避免的!
有没有办法在Spring Cloud Config服务器中的应用程序之间 "包含"(通过配置文件或其他方式!)共享配置属性?
更新
除了以下@vladsfl的正确答案之外,请注意如果您使用配置服务器上的本机配置文件来从文件系统或类路径而不是git repo提供配置,配置服务器将使用application.yml及其配置文件变体对于自己,但拒绝将其提供给其他应用程序.解决方案是用于spring.cloud.config.server.native.searchLocations从不同位置提取服务配置.
vla*_*sfl 11
是.您可以拥有application.yml或application-<profile>.yml在配置服务器上,现在使用此配置服务器的每个应用程序都将继承所有设置application.yml.在特定配置文件中运行的每个应用程序都将从中继承设置application-<profile>.yml.
可能已经太晚了,但如果其他人也遇到同样的问题,最终的解决方案如下:
您可以根据需要在 config-server 类路径下创建任意数量的 yml 文件。即使它在本机配置文件中选择,也会提供给客户端应用程序。之前唯一没有提到的是,您应该告诉客户端应用程序也读取这些设置文件。
这是一个工作示例:
resources
|-config
|-auth-service.yml - service specific configuration file
|-application.yml - config server settings
|-settings.yml - general settings file, planed to be loaded in every service
Run Code Online (Sandbox Code Playgroud)
spring:
application:
name: auth-service
cloud:
config:
username: "config-user"
password: "config-password-1234"
uri: "http://config-service:8888"
name: ${spring.application.name}, settings
Run Code Online (Sandbox Code Playgroud)
关键是name: ${spring.application.name}, settings告诉配置客户端从配置服务器加载以下设置:
${spring.application.name}这将加载config/auth-service.ymlsettings这将加载settings.yml| 归档时间: |
|
| 查看次数: |
3362 次 |
| 最近记录: |