spring cloud config:如何使用多个配置

use*_*027 7 java microservices spring-cloud-config

我想尝试一下:

我想尝试spring cloud config微服务项目,我有一个common config所有服务和multiple configs每个服务.
我知道如何使用多个profiles使用spring.profiles.activeinclude.我试图了解如何在配置客户端上加载多个配置?

是)我有的:

在我的git repo中,我有spring-config-repo我所拥有的......

application.yml
orderclient.yml
subscriberclient.yml
jmsclient.yml
productclient.yml
Run Code Online (Sandbox Code Playgroud)

config Server指向我的配置仓库.

spring:
  application:
  name: config-service
  cloud:
   config:
    server:
      git:
        uri: https://github.com/<user>/spring-config-repo

server:
 port: 8888
Run Code Online (Sandbox Code Playgroud)

我有我spring client想要使用多个配置的地方.在我的情况下orderService我想加载application.yml,orderclient.yml,jmsconfig.yml和For Product microService我需要'orderconfig.yml,jmsclient.yml,productclient.yml'

spring:
application:
  name: orderclient
profiles:
  active: test
cloud:
  config:
    uri: http://localhost:8888

###Any kind of config properties to load jmsclient, productclient?
Run Code Online (Sandbox Code Playgroud)

上面我可以从orderclient.yml访问属性.

我的问题:

问题1:

如何访问的性质jmsclient.yml,productclient.ymlorderclient应用.

问题2:

无论如何得到propertySources.name配置服务器暴露的所有列表?在上述情况下它应该显示出来

"propertySources": {
  "name": "https://github.com/<>/spring-config-repo/aplication.yml",
     "profiles": <available profiles for this say> Dev, Test,
  "name": "https://github.com/<>/spring-config-repo/orderclient.yml",
     "profiles": <available profiles for this say> Dev, Test
  "name": "https://github.com/<>/spring-config-repo/jmsclient.yml",
     "profiles": <available profiles for this say> Dev, Test
 ....}
Run Code Online (Sandbox Code Playgroud)

如果我的问题不明确或需要更多信息,请告诉我.谢谢.

pom*_*ine 12

您可以使用spring.cloud.config.name属性设置要加载的逗号分隔的配置列表:

spring.cloud.config.name: jmsclient,productclient,orderclient
Run Code Online (Sandbox Code Playgroud)

  • 这对我不起作用:bootstrap:spring.cloud.config.name = redis,jobster无法找到PropertySource并且设置了快速失败属性,失败:{“timestamp”:1625003088090,“status”:500,“error” :“内部服务器错误”,“异常”:“java.lang.IllegalStateException”,“消息”:“无法克隆或签出存储库”,“路径”:“/redis,jobster/dev”} 文档中没有任何内容 https ://cloud.spring.io/spring-cloud-config/multi/multi__spring_cloud_config_client.html#_ located_remote_configuration_resources 只是该标签可以用逗号分隔作为故障转移。 (2认同)