spring - 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 存储库中检索嵌套的配置文件?
解决方案
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
可以是任意字符串。
推荐阅读
- python - 从 i2c 连接的 Atlas Scientific 传感器将数据记录到 CSV 文件
- r - 如何在引用两个长度不等的表的日期范围内计算 sumifs?
- akka - 如何在akka中将第三方java类的实例序列化为protobuf
- python-3.x - 接收到的信号退出程序但不调用信号处理程序
- elasticsearch - 是否可以在 Elasticsearch 中获得多边形交集的转置?
- php - Laravel 5.6,动态创建属性
- java - 如何通过将 --patch-module javac 选项传递给我的项目编译器来使 Eclipse 在 JDK 9+ 上编译修补模块?(见图)
- azure - 通过令牌访问 Azure Web App 时访问被拒绝
- c# - 如何在 C# 代码后面调用 SQL 命令
- node.js - 发送多个子文档时,Mongoose 验证失败