我有一个本地配置服务器,它可以在像这样的 yml 配置设置中正常工作吗?
spring:
cloud:
config:
server:
git:
uri: https://github.com/xxx/xxxxx
search-paths:
- 'kenya*'
- 'tanzania*'
- 'uganda*'
- 'congo*'
- 'zimbabwe*'
在我的本地项目中,我可以访问所有这些存储库,例如
http://localhost:8888/uganda/dev
这将返回正确的文件以及预期的所选个人资料广告。
但是,当我设置 Pivotal Config 服务器时,无论我向路径添加什么参数,我都只会获得默认属性。
像这样https://configserver.cfapps.io/uganda/dev只返回存储库根目录下的默认属性。
我该如何使用
searchPaths 此处说明https://docs.run.pivotal.io/spring-cloud-services/config-server/configuring-with-git.html
添加我所有子文件夹的标志?
如果您使用 Pivotal Spring Cloud 服务,则可以使用多个创建服务,searchPaths
如下所示:
cf create-service -c '{ "git": { "uri": "https://github.com/dmikusa-pivotal/cook-config.git", "label": "search-paths", "searchPaths": "dev,prod" } }' cook-config-server
该searchPaths
参数仅采用逗号分隔的搜索路径/模式列表。
您指向的存储库应该具有名为dev
and 的顶级文件夹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
来获取令牌。然后在第二个请求中使用令牌从配置服务器实际请求一些数据。
如果您从多个搜索路径获取配置,您应该会看到这样的输出(请注意来自dev
和prod
子文件夹的数据):
{"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"}}]}
希望有帮助!
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句