Spring 提供嵌套纯文本文件的云配置服务器

Spring Cloud Config Server serving nested plain text files

我有一个配置服务器 运行,相关 application.yml 设置为

spring:
  application:
    name: config
    ...
      searchPaths:
        - '{application}'
        - '{application}/{profile}'

我想访问一个不是 application.properties 的文件,类似于 myfile.txt。如果我有 git 布局

/myapp/nested/folder/myfile.txt

我希望能够访问该文件。根据 the Spring Config Server docs,我应该可以通过 /{name}/{profile}/{label}/{path} 执行此操作,但我找不到任何工作路径。

TL;DR:如何通过配置服务器从 git 存储库检索嵌套的配置文件?

TL;DR:文档有误。端点 /{name}/{profile}/{label}/{path} 应该写成 /{application}/{profile}/{label}/{path}。您只需要确保您的 searchPaths/{path} 之一可以解析您的文件。


首先,{label} 一如既往地是 git 分支名称(可能是 "master")。

其次,{path}可以是文件的绝对路径。它使用 /,即 myapp/nested/folder/myfile.txt,而不是 {application}{label}.

中要求的 (_)

第三,问题中的搜索路径设置为'{application}''{application}/{profile}',以及/的默认搜索路径,git repo的根目录.这些定义了 Config Server 将搜索纯文本文件的位置:

/{expanded application}/{path}
/{expanded application}/{profile}/{path}
/{path}

请注意,只有 {application} 可以用 (_) 扩展到多个文件夹,只有 {path} 可以用 / 包含多个文件夹。例如,对于这些 searchPaths 和位于 /myapp/nested/folder/myfile.txt 的文件,以下请求有效:

/asdf/asdf/master/myapp/nested/folder/myfile.txt
/myapp/asdf/master/nested/folder/myfile.txt
/myapp/nested/master/folder/myfile.txt
/myapp(_)nested(_)folder/asdf/master/myfile.txt
/myapp(_)nested/folder/master/myfile.txt

其中 asdf 可以是任意字符串。