上一篇 <<<SpringCloud配置中心实现原理
下一篇 >>>SpringCloud配置更新后的刷新机制
1.环境创建
2.ConfigServer搭建
2.1jar包依赖
<!--spring-cloud 整合 config-server -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
2.2相关配置
spring:
application:
####注册中心应用名称
name: config-server
cloud:
config:
server:
git:
###git环境地址
uri: https://gitee.com/jarye/config.git
####搜索目录
search-paths:
- config
####读取分支
label: master
2.3项目启动
项目启动
@EnableConfigServer //开启分布式配置中心服务器端
@SpringBootApplication
public class ConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
}
}
读取配置文件信息 http://127.0.0.1:8888/config-client-dev.properties
3.ConfigClient配置
3.1jar包依赖
<!--spring-cloud 整合 config-client -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-client</artifactId>
</dependency>
3.2 配置信息
spring:
application:
####注册中心应用名称
name: config-client
cloud:
config:
####读取后缀
profile: dev
####读取config-server注册地址
discovery:
service-id: config-server
enabled: true
3.3配置文件读取
读取配置文件
@RestController
public class IndexController {
@Value("${name}")
private String name;
@RequestMapping("/name")
private String name() {
return name;
}
}
推荐阅读:
<<<传统配置的缺陷与常用分布式配置中心介绍
<<<SpringCloud配置中心实现原理
<<<SpringCloud配置更新后的刷新机制
<<<Apollo配置中心总体设计原理
<<<Apollo客户端与服务端同步原理
<<<Apollo配置更新的推送机制
<<<Apollo单机环境搭建
<<<Apollo多环境部署
<<<Apollo操作手册之基础配置
<<<Apollo操作手册之项目设置
<<<Apollo操作手册之配置说明汇总
<<<Apollo操作手册之配置集群环境
<<<Apollo操作手册之Namespace管理
<<<Apollo操作手册之配置增删改操作
<<<Apollo操作手册之配置同步发布和回滚操作
<<<Apollo操作手册之配置灰度发布
<<<Apollo在代码中使用时的配置信息
<<<Apollo配置信息被程序识别的方式