从带有子文件夹的 Spring Cloud 配置存储库中获取属性

Ali*_*ouf 2 spring-boot spring-cloud-config

我正在尝试为我的配置存储库建立一个文件夹结构。

\n
root\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 serviceA\n\xe2\x94\x82   \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 application-dev.properties\n\xe2\x94\x82   \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 application-prod.properties\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 serviceB\n\xe2\x94\x82   \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 application-dev.properties\n\xe2\x94\x82   \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 application-prod.properties\n
Run Code Online (Sandbox Code Playgroud)\n

在我的配置服务器中,我有以下内容application.yml

\n
server:\n  port: 8081\nspring:\n  application:\n    name: cloud-config-server\n  cloud:\n    config:\n      server:\n        monitor:\n          github:\n            enabled: true\n          gitee:\n            enabled: true\n        git:\n          password: ${PASSWORD}\n          username: ${USERNAME}\n          uri: ${LINK_TO_CONFIG}\n          default-label: master\n          search-paths: serviceA, serviceB\n
Run Code Online (Sandbox Code Playgroud)\n

当运行服务器并请求时http://localhost:8081/serviceA/prodhttp://localhost:8081/serviceB/prod我得到相同的结果

\n
{\n   "name":"serviceA",\n   "profiles":[\n      "prod"\n   ],\n   "label":null,\n   "version":"9df32c9dbd11be65e892caf878ddc8d16906a849",\n   "state":null,\n   "propertySources":[\n      {\n         "name":"GITHUB_URI/springcloudconfigrepo/serviceB/application-prod.properties",\n         "source":{\n            "profile":"some-service-prod"\n         }\n      },\n      {\n         "name":"GITHUB_URI//springcloudconfigrepo/serviceA/application-prod.properties",\n         "source":{\n            "profile":"another-service-prod"\n         }\n      }\n   ]\n}\n
Run Code Online (Sandbox Code Playgroud)\n

我的问题是,如何仅获取 serviceA (或 serviceB)的属性?

\n

我在github上的spring cloud配置服务器在这里

\n

Ser*_*ago 6

您需要将配置设置为searchPaths您的应用程序名称。

配置应该如下所示:

spring:
  cloud:
    config:
      server:
        git:
          uri: ${LINK_TO_CONFIG}
          searchPaths: '{application}'
Run Code Online (Sandbox Code Playgroud)