如果您使用的是关键的Spring云服务,那么可以使用多个
searchPaths
这样地:
cf create-service -c '{ "git": { "uri": "https://github.com/dmikusa-pivotal/cook-config.git", "label": "search-paths", "searchPaths": "dev,prod" } }' cook-config-server
这个
搜索路径
参数只接受以逗号分隔的搜索路径/模式列表。
然后,指向的存储库应该具有名为
dev
和
prod
. 配置服务器将返回
<app-name>.properties
(它支持的所有其他变体)在“搜索路径”文件夹中。
通过运行以下命令,可以验证是否接收到多个搜索路径值的数据:
curl -k -H "Authorization: bearer $(curl -k -s -X POST 'https://p-spring-cloud-services.uaa.<system_domain>/oauth/token' -d 'grant_type=client_credentials&client_id=<insert client id>&client_secret=<insert client_secret>' | jq .access_token | cut -d '"' -f 2)" <insert uri>/cook/prod
你需要替换
<system_domain>
以系统域为基础,
<insert client id>
和
<insert client secret>
使用服务实例的客户端id和机密(运行
cf env <app>
针对具有绑定SCS配置服务器以获取这些值的应用程序)。
这个命令可以做两件事。首先,它将使用
client_id
和
client_secret
去拿一个代币。然后,在第二个请求中使用该令牌从配置服务器实际请求一些数据。
如果从多个搜索路径获取配置,则应该看到这样的输出(注意
开发
和
产品
子文件夹):
{"name":"cook","profiles":["prod"],"label":null,"version":"5d5a3f26022dd00becdbad855c7d27ae530685f7","state":null,"propertySources":[{"name":"https://github.com/dmikusa-pivotal/cook-config.git/prod/cook.properties","source":{"cook.special":"Prod Config"}},{"name":"https://github.com/dmikusa-pivotal/cook-config.git/dev/cook.properties","source":{"cook.special":"Dev Config"}},{"name":"https://github.com/dmikusa-pivotal/cook-config.git/cook.properties","source":{"cook.special":"Not in Folder config"}}]}
希望能有帮助!