1.概述
spring-cloud-config是springcloud提供的一种在线配置系统,对于集群可以做到在一个地方配置,在整个集群都可以拉取使用。
2.使用
服务端
pom文件
<dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-config-server</artifactId> </dependency> </dependencies>
application
server:
port: 8001
spring:
application:
name: cloud-config-server
cloud:
config:
server:
git:
uri: https://gitee.com/tqlin/spring-boot-demo.git #因为github有时候不稳定,我这里改到了码云仓
searchPaths: /cloud-config/config-repo/ #配置文件目录
force-pull: true
启动类
@EnableConfigServer
@SpringBootApplication
public class CloudConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(CloudConfigServerApplication.class, args);
}
}
3.原理
cloud-config本身并不是分布式的,但是数据可以保存在分布式的中间件中,如reids。也可以保存在mysql,git中。
每一个应用对应于一套envriment,envriment下有很多EnvironmentRepository来负责数据加载。
扫描二维码关注公众号,回复:
11393559 查看本文章