在 Spring Cloud Config 中,如果您有一个包含 /
的分支(标签),它不会从云配置服务器获取正确的分支。
考虑我们产品 TheApp
的 bootstrap.yml
中的以下属性;
spring:
application:
name: TheApp
profiles:
active: test
cloud:
config:
uri: http://myconfigserver.com
我们为我的云配置标签添加了分支feature/new
,直接使用它,如下所示;
spring:
cloud:
config:
label: feature/new
因为这将转换为以下从我们的 TheApp
应用程序对配置服务器的 RESTful 调用;
http://myconfigserver.com/{name}/{profile}/{label}
这将是;
http://myconfigserver.com/TheApp/test/feature/new
尽管很明显,由于我们的标签名称中存在额外的 /
,此调用将不起作用。如何在此配置中使用包含 /
的标签?
最佳答案
解决方案非常简单,只需将中断对配置服务器的调用的 /
替换为 (_)
,例如 feature/new
将是 bootstrap.yml 中的 feature(_)new
;
spring:
cloud:
config:
label: feature(_)new
对配置服务器的 RESTful 调用将是;
http://myconfigserver.com/TheApp/test/feature(_)new
这将成功获取正确的分支,即feature/new
关于spring - 如何在 Spring Cloud Config 中转义分支名称(标签)中的斜杠字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43435897/