为Spring Cloud Config Server配置远程git仓库
2018-05-09 11:41
786 查看
简介
虽然在开发过程,在本地创建git仓库操作起来非常方便,但是在实际项目应用中,多个项目组需要通过一个中心服务器来共享配置,所以Spring Cloud配置中心支持远程git仓库,以使分散的项目组更方便的进行协作。基础环境
JDK 1.8Maven 3.3.9
IntelliJ 2018.1
Git
项目源码
Gitee码云配置远程git仓库
首先我在gitee上创建了一个远程仓库https://gitee.com/zxuqian/spring-cloud-config-remote专门用来存放配置文件,然后我们会通过配置文件来访问此仓库。然后我们把以前本地的配置文件迁移到此库中。为了测试效果,我们把
web-client.yml的
message的值修改为:
此条消息来自于远程配置仓库
配置configserver
现在在我们之前的configserver中作一些配置上的改动。首先为了保留之前的本地仓库的配置,我们把application.yml重命名为
application-local.yml。
这个
-local是一个
profile,它的值是
-后面的,即
local,我们可以在
bootstrap.yml中指定使用哪个
profile。比如实际项目中开发阶段和生产阶段的配置有所不同,所以会有
application-development.yml和
application-production.yml等两种或以上的配置。
然后新建一个
application-remote.yml文件,添加如下配置内容:
server: port: 8888 spring: cloud: config: server: git: uri: https://gitee.com/zxuqian/spring-cloud-config-remote username: 您的gitee用户名 password: 您的gitee密码
因为是自用账号的仓库,所以就不提供账号密码了,改成自己对应的。这里
uri配置了远程git仓库的地址。
最后在
bootstrap.yml中启用我们的
remoteprofile:
spring: application: name: config-server profiles: active: remote
spring.profiles.active即指定了我们的
remoteProfile,使用
application-remote.yml配置文件。
测试
使用spring-boot:run启动我们的config server,然后访问
http://localhost:8888/web-client/default,看到如下结果:
{"name":"web-client","profiles":["default"],"label":null,"version":"cbef7d379ef01d68810c3fdc2105b2226ea6c611","state":null,"propertySources":[{"name":"https://gitee.com/zxuqian/spring-cloud-config-remote/web-client.yml","source":{"message":"此条消息来自于远程配置仓库","management.endpoints.web.exposure.include":"*"}}]}
message的值取自于远程仓库。这里的
web-client/default是
配置文件名/profile,因为我们的web客户端项目没有其他Profile,则默认值为
default,只有这样写全,才可以访问到
web-client.yml的配置。
相关文章推荐
- 为Spring Cloud Config Server配置远程git仓库
- (Spring Cloud微服务实战-书中之坑)spring cloud config优先读取本地配置,其次读取git仓库
- spring cloud config server使用svn来作为外部配置中心
- spring cloud config server 配置中心
- spring cloud config server 使用本地配置文件报错
- spring cloud config 用svn做配置文件仓库
- SpringCloud系列九:SpringCloudConfig 基础配置(SpringCloudConfig 的基本概念、配置 SpringCloudConfig 服务端、抓取配置文件信息、客户端使用 SpringCloudConfig 进行配置、单仓库目录匹配、应用仓库自动选择、仓库匹配模式)
- Spring Cloud之config server(配置中心)
- Spring Cloud Config Server 配置说明
- spring cloud config 配置自建git服务器
- 关于spring-cloud-config配置中心远程拉取有时失败问题记录
- 干货实操:微服务Spring Cloud 系列(一) Spring cloud Config 用SVN做配置仓库
- spring cloud config 之svn仓库配置与动态刷新(服务端)
- Spring Cloud Config Server基于本地git使用SSH clone github repository
- eclispe git config配置文件配置远程仓库
- spring cloud config 配置自建git服务器报错解决
- Spring Cloud Config采用Git存储时两种常用的配置策略
- spring cloud config-server 高可用配置中心
- Spring Cloud Config 之svn配置仓库与动态刷新(客户端手动手动刷新)
- spring-cloud-config-server之拉取git失败解决方案