SpringCloud 微服务统一配置中心 Config Server ( 一 )
一、创建Config Server项目
config server 本身就是一个微服务项目
二、启动类添加注册
@EnableDiscoveryClient : 向注册中心注册的功能
@EnableConfigServer : 配置中心的功能
三、添加配置
需要添加一个远程 github仓库地址存放配置文件。
远程 git 中存放配置
四、启动项目测试
-
启动项目,去浏览去访问:
localhost:9001/order-a.properties
localhost:9001/order-a.yml
localhost:9001/order-a.json
以上格式都可以。 -
在解释一下上面的访问路径:
日志里提供了多种访问方式,举两个例子吧
/{name}-{profiles}.properties]
/{label}/{name}-{profiles}.properties]
name 指服务名,就是上面的order
profiles 指环境,文件名中环境如果没不能匹配,则默认访问 order.properties 文件
label 指分支名,默认是 master分支