如何要求Spring Cloud Config服务器从特定分支中检出配置? [英] How to ask Spring Cloud Config server to checkout configuration from specific branch?
问题描述
我有以下Spring cloud config application.yml:
I have following 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
以下是我对用户微服务的 bootstrap.yml
:
Following is my bootstrap.yml
of user microservice:
spring:
application:
name: userservice
cloud:
config:
uri: http://localhost:8881/
场景-1
当我在浏览器中按如下所示访问配置服务器时: http://localhost:8881/development/userservice-development.yml
它可以正确提供文件.当我查看 basedir
(即target/config)时,我看到:
Scenario - 1
When I hit config server in browser like this:
http://localhost:8881/development/userservice-development.yml
It serves file properly. and when I look at basedir
i.e. target/config, I see:
- userservice.yml
- gateway.yml
正是我想要的,因为我仅在开发分支中添加了这两个文件.
场景-2
当我使用以下命令运行用户服务微服务项目时: mvn clean spring-boot:run -Dspring.profiles.active = development
它从git中获取了正确的文件,但是它是从master分支中签出的!,但是不是从开发分支中签出的,正如我所期望的那样.我期待的对吗?(仅供参考,我在master分支中同时拥有开发和生产yml)
It fetches the right file from git, but it checkout from master branch ! but not from the development branch as I am expecting. am I expecting right ? (FYI I have both development and production yml in master branch)
所以问题是,如何使用配置服务器?我们是否可以设置任何配置以仅从该特定分支获取yml?我相信我们需要设置一些标签,因为根据文档,默认标签为master.谁能告诉我在上述情况下如何设置标签?
So the question is, how do we go for using config server ? Is there any configuration which we can set to fetch yml from that particular branch only ? I believe we need to set some label, because as per documentation, default label is master. Can anyone let me know how do we go for setting label in above scenario ?
推荐答案
According to the documentation, the configuration you want to set in your config client is:
spring.cloud.config.label=mybranch
其中 mybranch
是git存储库中的现有分支.
Where mybranch
is an existing branch in your git repo.
这篇关于如何要求Spring Cloud Config服务器从特定分支中检出配置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!