如何从 Spring Cloud Config Server 读取多个配置文件 [英] How to read multiple config file from Spring Cloud Config Server

查看:114
本文介绍了如何从 Spring Cloud Config Server 读取多个配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Spring 云配置服务器支持读取名为 ${spring.application.name}.properties 的属性文件.但是,我的应用程序中有 2 个属性文件.

Spring cloud config server supports reading property files with name ${spring.application.name}.properties. However I have 2 properties files in my application.

a.properties
b.properties

我可以让配置服务器读取这两个属性文件吗?

Can I get the config server to read both these properties files?

推荐答案

重命名 git 或配置服务器正在查看的文件系统中的属性文件.

Rename your properties files in git or file system where your config server is looking at.

a.properties -> <your_application_name>.properties
a.properties -> <your_application_name>-<profile-name>.properties

例如,如果您的应用程序名称是 test 并且您在 dev 配置文件上运行您的应用程序,则以下两个属性将一起使用.

For example, if your application name is test and you are running your application on dev profile, below two properties will be used together.

test.properties
test-dev.properties

您还可以在配置客户端的 bootstrap.properties 中指定其他配置文件,以检索更多属性文件,如下所示.例如,

Also you can specify additional profiles in bootstrap.properties of your config client to retrieve more properties files like below. For example,

spring:
  profiles: dev
  cloud:
    config:
      uri: http://yourconfigserver.com:8888
      profile: dev,dev-db,dev-mq

如果你像上面一样指定,下面的所有文件将一起使用.

If you specify like above, below all files will be used together.

test.properties
test-dev.properties
test-dev-db.prpoerties
test-dev-mq.properties

这篇关于如何从 Spring Cloud Config Server 读取多个配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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