首页 > 解决方案 > Spring Cloud Config Server 提供嵌套的纯文本文件

问题描述

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

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

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

/myapp/nested/folder/myfile.txt

我希望能够访问该文件。根据Spring Config Server docs,我应该可以通过 来做到这一点/{name}/{profile}/{label}/{path},但我无法获得任何工作路径。

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

标签: springspring-cloudconfigserver

解决方案


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


首先{label},与往常一样,git 分支名称(可能是“master”)。

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

第三,问题中的搜索路径设置为 '{application}'和,以及git repo 的根目录'{application}/{profile}'的默认搜索路径。/这些将 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

whereasdf可以是任意字符串。


推荐阅读