阅读文本大概需要 3 分钟。
上一篇文章:Spring Cloud:分布式配置中心详解(上)我们主要介绍了如何搭建 Config Server,但是没有介绍 Config Client 如何通过 Config Server 和 GitHub 通信。这一篇文章我们继续。
之前我们写代码,客户端都是直接通过 application.yml 配置文件,获取相关的配置,也就是说,配置信息都写在服务本身的 application.yml 里了。现在客户端通过 Config Server(即配置中心),能否获取到我们传在 GitHub 上的配置呢?
我们新建一个客户端的 model 工程,取名为:microservice-config-client。导入 config 依赖:
<dependency>
<groupId>org.springframework.cloudgroupId>
<artifactId>spring-cloud-starter-configartifactId>
dependency>
然后在 resource 目录下新建一个 bootstrap.yml 文件,application.yml 是用户级的资源配置项