上一篇: 微服务(十三)—— 单点登录.
1. 介绍
对于微服务而言,服务比较多,而且每个服务都需要配置文件,而且配置文件如果需要修改,就需要重新启动服务,这无疑比较麻烦。Spring Cloud 提供了Spring Cloud Config 来做配置中心。
2. 项目
2.1 创建远程仓库
首先我们可以将配置文件放在远程,Spring Cloud Config支持Git,所以可以将配置文件放在Git。由于Git访问比较慢,所以我将配置文件放在了Gitee.
在Gitee创建一个仓库,然后将配置文件都放在这个远程仓库里,backend-config-center.
2.2 创建本地项目
然后本地创建一个Spring Boot项目,引入Spring Cloud Config依赖,如下:
<!-- 引入父依赖 -->
<parent>
<groupId>com.aiun</groupId>
<artifactId>BackendManageSystem</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server