![](/img/trans.png)
[英]spring cloud config client not loading configuration from config server
[英]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
即目標/配置時,我看到:
- userservice.yml
- gateway.yml
正是我想要的,因為我只在 development 分支中添加了這兩個文件。
場景 - 2
當我使用以下命令運行我的 userservice 微服務項目時:
mvn clean spring-boot:run -Dspring.profiles.active=development
它從 git 獲取正確的文件,但它從 master 分支檢出! 但不是像我期望的那樣來自開發分支。 我期待對嗎? (僅供參考,我在主分支中有開發和生產 yml)
所以問題是,我們如何使用 config server ? 是否有任何配置可以設置為僅從該特定分支獲取 yml? 我相信我們需要設置一些標簽,因為根據文檔,默認標簽是 master。 誰能讓我知道我們如何在上述情況下設置標簽?
如果客戶端未指定標簽,您可以通過屬性spring.cloud.config.server.git.default-label
指定配置服務器使用的默認分支(更一般地說,Git 標簽),也許這就是您所追求的? 當然可以為我解決問題!
配置服務器旨在使用配置文件來分離環境。 例子:
/{application}/{profile}[/{label}]
/{application}-{profile}.yml
/{label}/{application}-{profile}.yml
/{application}-{profile}.properties
/{label}/{application}-{profile}.properties
分支使配置不一致。
配置服務器的概念基於 12-factor config ( http://12factor.net/config )。
檢查它的詳細原因。
如果只使用 yml 文件中的分支,只需配置:
spring:
cloud:
config:
server:
git:
uri: https://gitlab.com/somerepo.git
username: someuser
password: somepass
default-label: branchname
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.