弹簧云配置:如何使用多个配置

2022-09-04 01:31:51

我想尝试什么:

我想尝试微服务项目,其中我为所有服务和每个服务提供了一个。
我了解了如何使用多个使用和.我正在尝试了解如何在配置客户端上加载多个配置?spring cloud configcommon configmultiple configsprofilesspring.profiles.activeinclude

我有什么:

在我的git存储库中,我有我拥有的地方...spring-config-repo

application.yml
orderclient.yml
subscriberclient.yml
jmsclient.yml
productclient.yml

我已指向我的配置存储库。config Server

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

server:
 port: 8888

我有我想使用多个配置的地方。在我的情况下,我想加载,对于产品微服务,我需要'orderconfig.yml,jmsclient.yml,productclient.yml'spring clientorderServiceapplication.yml,orderclient.yml,jmsconfig.yml

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

###Any kind of config properties to load jmsclient, productclient?

上面我可以从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
 ....}

如果我的问题不清楚或需要更多信息,请告诉我。谢谢。


答案 1

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

spring.cloud.config.name: jmsclient,productclient,orderclient

答案 2

推荐