在前面的博客中,我们都是将配置文件放在各自的服务中,但是这样做有一个缺点,一旦配置修改了,那么我们就必须停机,然后修改配置文件后再进行上线,服务少的话,这样做还无可厚非,但是如果是成百上千的服务了,这个时候,就需要用到分布式的配置管理了。而spring cloud config正是用来解决这个问题而生的。下面就结合gitlab来实现分布式配置中心的搭建。spring cloud config配置中心由server端和client端组成,
前提:在gitlab中的工程下新建一个配置文件configserver-dev.properties
一、配置Server
1、添加依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
2、在Application主类开启支持
@EnableConfigServer
3、配置application.yml文件
server:
port: 8888
spring:
application:
name: config
cloud:
config:
server:
git:
uri: https://gitlab.xxx.com/xxxxx/xxxxx.git # 配置gitlab仓库的地址,注意,此处必须以.git结尾
search-paths: /config-repo # gitlab仓库地址下的相对地址,可以配置多个,用,分