如何在Spring Cloud Config中的分支名称(标签)中转义斜杠字符

bur*_*ete 3 spring spring-boot spring-cloud-config

在Spring Cloud Config中,如果您的分支(标签)包含/,则不会从云配置服务器获取正确的分支。

考虑bootstrap.yml我们产品的以下特性TheApp;

spring:
  application:
    name: TheApp
  profiles:
    active: test
  cloud:
    config:
      uri: http://myconfigserver.com
Run Code Online (Sandbox Code Playgroud)

而且,我们feature/new为我的云配置标签添加了分支,如下所示直接使用它;

spring:
  cloud:
    config:
      label: feature/new
Run Code Online (Sandbox Code Playgroud)

由于这将转换为以下从我们的TheApp应用程序对配置服务器的RESTful调用;

http://myconfigserver.com/{name}/{profile}/{label}
Run Code Online (Sandbox Code Playgroud)

将会是;

http://myconfigserver.com/TheApp/test/feature/new
Run Code Online (Sandbox Code Playgroud)

尽管很明显,由于/我们的标签名称多余,所以该调用无法正常工作。如何使用/此配置中包含的标签?

bur*_*ete 5

解决方案非常简单,只需使用替换替换即可/中断对配置服务器的调用(_),因此例如feature/newfeature(_)new在我们的bootstrap.yml中;

spring:
  cloud:
    config:
      label: feature(_)new
Run Code Online (Sandbox Code Playgroud)

RESTful对配置服务器的调用将是;

http://myconfigserver.com/TheApp/test/feature(_)new
Run Code Online (Sandbox Code Playgroud)

这将成功获取正确的分支,即 feature/new

更多细节; 在这里这里检查。