Quick Start
在分布式系统中,由于服务数量巨多,为了方便服务配置文件统一管理,实时更新,所以需要分布式配置中心组件。在Spring Cloud中,有分布式配置中心组件spring cloud config ,它支持配置服务放在配置服务的内存中(即本地),也支持放在远程Git仓库中。在spring cloud config 组件中,分两个角色,一是config server,二是config client。
构建Config Server
创建一个Spring Boot项目,pom.xml文件如下:
1 |
|
application.properties配置文件如下:
1 | config-server = |
最后是Application.java
1 | package com.fiveplus; |
接下来在你的git仓库下新建一个文件夹,这个文件夹名与application.properties文件中的spring.cloud.config.server.git.search-paths一致。
http请求地址与资源文件映射:
- /{application}/{profile}[/{label}]
- /{application}-{profile}.yml
- /{label}/{application}-{profile}.yml
- /{application}-{profile}.properties
- /{label}/{application}-{profile}.properties
结束
可以使用Docker的方式构建该项目。