如何让Spring Cloud Config服务器检查特定分支的配置?

agp*_*gpt 12 git spring spring-mvc spring-boot spring-cloud

我有以下Spring cloud config 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  
Run Code Online (Sandbox Code Playgroud)

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

spring: 
  application: 
    name: userservice
  cloud: 
    config: 
      uri: http://localhost:8881/  
Run Code Online (Sandbox Code Playgroud)

场景 - 1
当我在浏览器中点击配置服务器时:
http://localhost:8881/development/userservice-development.yml
它正确地提供文件.当我看到basedir目标/配置时,我看到:

- userservice.yml  
- gateway.yml  
Run Code Online (Sandbox Code Playgroud)

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

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

它从git中获取正确的文件,但它从master分支结账!不是我期待的开发分支.我期待对吗?(仅供参考我在master分支中有开发和生产yml)

所以问题是,我们如何使用配置服务器?是否有任何配置我们可以设置为仅从该特定分支获取yml?我认为我们需要设置一些标签,因为根据文档,默认标签是master.任何人都可以让我知道我们如何在上述场景中设置标签?

spe*_*ibb 24

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

spring.cloud.config.label=mybranch
Run Code Online (Sandbox Code Playgroud)

mybranch您的git仓库中的现有分支在哪里.

  • 谁称分支为“标签”?称之为分支应该是 `spring.cloud.config.branch` (6认同)
  • 谢谢.我将标签全部设置到配置服务器中.这就是配置客户端应用程序中的绑定吗?在服务器或客户端的"spring.cloud.config"属性之间做出决定是很困惑的. (3认同)
  • 对我来说,上述属性不起作用,当我更改为以下属性时,它工作得很好 spring.cloud.config.server.git.default-label = BranchName 。我正在使用 Spring Boot 版本 2.1.3.RELEASE 和 spring-cloud-config-server 版本 2.1.1.RELEASE。 (3认同)
  • 我的分支有一个斜杠(/),那么如何配置呢?我尝试了`spring.cloud.config.label = release / 1.0.0,release_1.0.0,release(_)1.0.0`,但是不起作用 (2认同)
  • 我想通了。应该是`release(_)1.0.0` (2认同)

Mat*_*ise 15

如果客户端没有通过属性指定标签,您可以指定配置服务器使用的默认分支(更一般地说,Git标签)spring.cloud.config.server.git.default-label,也许这就是您所追求的?当然为我解决了这个问题!


Hle*_*lex 10

配置服务器旨在使用配置文件来分离环境.例:

/{application}/{profile}[/{label}]
/{application}-{profile}.yml
/{label}/{application}-{profile}.yml
/{application}-{profile}.properties
/{label}/{application}-{profile}.properties
Run Code Online (Sandbox Code Playgroud)

分支使配置不一致.

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

查看详细原因.


小智 8

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

spring:
  cloud:
    config:
      server:
        git: 
          uri: https://gitlab.com/somerepo.git
          username: someuser
          password: somepass
          default-label: branchname
Run Code Online (Sandbox Code Playgroud)

  • Branchname 也不应该包含斜杠 /,否则将无法工作 (3认同)