如何要求 Spring Cloud Config 服务器从特定分支签出配置?

How to ask Spring Cloud Config server to checkout configuration from specific branch?

我有以下 Spring 云配置 application.yml:

spring: 
  application: 
    name: configserver
  cloud: 
    config: 
      server: 
        git: 
          uri: https://xyz@bitbucket.org/xyz/microservices-configs.git
          username: xyz
          password: xyz
          basedir: target/configs
server:
  port: 8881  

以下是我的bootstrap.yml用户微服务:

spring: 
  application: 
    name: userservice
  cloud: 
    config: 
      uri: http://localhost:8881/  

场景 - 1
当我像这样在浏览器中点击配置服务器时:
http://localhost:8881/development/userservice-development.yml
它正确地提供文件。当我查看 basedir 即 target/config 时,我看到:

- userservice.yml  
- gateway.yml  

正是我想要的,因为我只在开发分支中添加了这两个文件

场景 - 2
当我 运行 我的用户服务微服务项目使用以下命令时:
mvn clean spring-boot:run -Dspring.profiles.active=development

它从 git 获取正确的文件,但是 它从主分支检出! 不是从开发分支检出 正如我所期待的。我期待对吗? (仅供参考,我在 master 分支中同时拥有开发和生产 yml)

所以问题是,我们如何去使用配置服务器?有没有我们可以设置为仅从该特定分支获取 yml 的配置?我相信我们需要设置一些标签,因为根据文档,默认标签是 master。谁能告诉我在上述情况下我们如何设置标签?

配置服务器旨在使用配置文件来分隔环境。 示例:

/{application}/{profile}[/{label}]
/{application}-{profile}.yml
/{label}/{application}-{profile}.yml
/{application}-{profile}.properties
/{label}/{application}-{profile}.properties

分支使配置不一致。

配置服务器的概念基于 12 因素配置 (http://12factor.net/config)。

查看详细原因。

根据documentation,您要在配置客户端中设置的配置是:

spring.cloud.config.label=mybranch

其中 mybranch 是您的 git 存储库中的现有分支。

如果客户端未指定标签,您可以通过 属性 spring.cloud.config.server.git.default-label 指定配置服务器使用的默认分支(更一般地说,Git 标签),也许这个你在追求什么?绝对能解决我的问题!

如果只使用yml文件中的分支只需配置:

spring:
  cloud:
    config:
      server:
        git: 
          uri: https://gitlab.com/somerepo.git
          username: someuser
          password: somepass
          default-label: branchname