Spring Cloud Config Server 不在本机模式下提供特定于应用程序的属性

Spring Cloud Config Server does not serve application-specific properties in native mode

我有一个 Spring 云配置服务器 v3.0.5,它提供来自 Git 存储库的配置属性,如下所示:

|
|-- foo-service/
|   |-- application.yml
|-- bar-service/
|   |-- application.yml
|-- application-common.yml
|-- application-kafka.yml
|-- ...

如您所见,每个微服务都有一个子目录,其中包含特定于应用程序的配置和根目录中的一些常见配置,我们可以通过配置文件(common、kafka 等)获取这些配置

因此,例如,我们可以像这样获取 应用程序特定的 and/or 配置文件特定的配置属性

# Successfully returns application-specific properties
curl http://<CONFIG_SERVICE_URL>/foo-service-application.yml
# Successfully returns application-specific + common + kafka properties
curl http://<CONFIG_SERVICE_URL>/foo-service-application,common,kafka.yml

但是,在开发过程中,我们希望使用基于文件的本机存储库,这样我们就不需要提交每个配置更改并轻松地在本地进行测试。

因此,在配置服务器中,我将活动配置文件设置为 native,并将 spring.cloud.config.server.native.search-locations 设置为相同的存储库路径。

但是当我尝试获取特定于应用程序的配置(即子目录中的配置文件)时,它 return 是空的:

# This returns empty response:
curl http://<CONFIG_SERVICE_URL>/foo-service-application.yml
{}

# This returns only profile-specific configs but **omits** foo-service applcations configs:
curl http://<CONFIG_SERVICE_URL>/foo-service-application,common,kafka.yml
...

我在这里错过了什么?为什么它不能 return 特定于应用程序的属性?我必须为配置服务器设置另一个配置吗?

感谢任何帮助。谢谢。

好的,我终于找到了!
显然,我们需要在 spring.cloud.config.server.native.search-locations 属性 中明确指定带有 application 占位符 的子目录,这是 IMO 模糊描述的 here in docs:

The search locations can contain placeholders for {application}, {profile}, and {label}. In this way, you can segregate the directories in the path and choose a strategy that makes sense for you (such as subdirectory per application or subdirectory per profile).

因此,就我而言,我必须将 search-locations 定义为:

spring:
  cloud:
    config:
      server:
        native:
         search-locations:
          - /path/to/config/repo
          - /path/to/config/repo/{application}

现在它可以正确地服务于特定于应用程序和特定于配置文件的配置属性。

虽然这足以满足我的情况,但我仍然不知道为什么基于文件的方法和基于 git 的方法有如此大的不同(即为什么我们应该明确地为特定于应用程序的配置设置子目录基于文件的方法,而它可以在基于 git 的方法中自动为它们提供服务?)