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仓库中的现有分支在哪里.
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)
| 归档时间: |
|
| 查看次数: |
21321 次 |
| 最近记录: |