SpringCloud的配置管理:Spring Cloud Config
演示如何使用ConfigServer提供统一的参数配置服务
###################################################################
一、概念和定义
1、
2、
3、
###################################################################
二、开发案例-服务端
#*******************************************************
1、引入pom依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
#*******************************************************
2、引入应用注解
@EnableConfigServer
@SpringBootApplication
public class ConfigServerApp
{
public static void main(String[] args)
{
SpringApplication.run(ConfigServerApp.class, args);
}
}
#*******************************************************
3、编写配置文件,上传到git
ConfigClient-dev.properties
#-------------------------------------------------
UserKey=ConfigClient.dev.key
UserVal=ConfigClient.dev.val
driverClassName=com.mysql.jdbc.Driver
user=root
password=ConfigClient_dev_123
url=jdbc:mysql:///db_user_ConfigClient_dev
ConfigClient-tst.properties
#-------------------------------------------------
UserKey=ConfigClient.tst.key
UserVal=ConfigClient.tst.val
driverClassName=com.mysql.jdbc.Driver
user=root
password=ConfigClient_tst_123
url=jdbc:mysql:///db_user_ConfigClient_tst
#*******************************************************
4、启动服务端测试
http://localhost:8000/ConfigClient/dev/master
http://localhost:8000/ConfigClient/tst/master
http://localhost:8000/ConfigClient2/dev/master
http://localhost:8000/ConfigClient2/tst/master
http://localhost:8000/jdbc/dev/master
http://localhost:8000/jdbc/tst/master
###################################################################
三、开发案例-客户端
#*******************************************************
1、引入pom依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-client</artifactId>
</dependency>
#*******************************************************
2、bootstrap.properties
spring.application.name=ConfigClient2
server.port=8822
spring.cloud.config.name=ConfigClient2
spring.cloud.config.profile=pro
spring.cloud.config.uri=http://localhost:8000
spring.cloud.config.label=master
#*******************************************************
3、编写获取配置代码
@RestController
public class ConfigController {
@Value("${driverClassName}")
private String driverClassName;
@Value("${user}")
private String user;
@Value("${password}")
private String password;
@Value("${url}")
private String url;
@PostConstruct
@RequestMapping(value = "/showJdbc")
public String show() {
System.out.println("driverClassName=" + driverClassName);
System.out.println("user=" + user);
System.out.println("password=" + password);
System.out.println("url=" + url);
return "driverClassName="+driverClassName+",<br/>user="+user+",<br/>password="+password+",<br/>url="+url+"<br/>";
}
}
#*******************************************************
4、启动客户端测试
http://localhost:8811/showJdbc
http://localhost:8822/showJdbc
###################################################################
四、代码下载
https://github.com/lexiaofei/workspace_SpringConfig.git
SpringCloud的配置管理:Spring Cloud Config的更多相关文章
- 【SpringCloud】第七篇: 高可用的分布式配置中心(Spring Cloud Config)
前言: 必需学会SpringBoot基础知识 简介: spring cloud 为开发人员提供了快速构建分布式系统的一些工具,包括配置管理.服务发现.断路器.路由.微代理.事件总线.全局锁.决策竞选. ...
- 【SpringCloud】第六篇: 分布式配置中心(Spring Cloud Config)
前言: 必需学会SpringBoot基础知识 简介: spring cloud 为开发人员提供了快速构建分布式系统的一些工具,包括配置管理.服务发现.断路器.路由.微代理.事件总线.全局锁.决策竞选. ...
- 跟我学SpringCloud | 第六篇:Spring Cloud Config Github配置中心
SpringCloud系列教程 | 第六篇:Spring Cloud Config Github配置中心 Springboot: 2.1.6.RELEASE SpringCloud: Greenwic ...
- 微服务SpringCloud之Spring Cloud Config配置中心Git
微服务以单个接口为颗粒度,一个接口可能就是一个项目,如果每个项目都包含一个配置文件,一个系统可能有几十或上百个小项目组成,那配置文件也会有好多,对后续修改维护也是比较麻烦,就和前面的服务注册一样,服务 ...
- SpringCloud(6)分布式配置中心Spring Cloud Config
1.Spring Cloud Config 简介 在分布式系统中,由于服务数量巨多,为了方便服务配置文件统一管理,实时更新,所以需要分布式配置中心组件.在Spring Cloud中,有分布式配置中心组 ...
- SpringCloud教程 | 第六篇: 分布式配置中心(Spring Cloud Config)
一.简介 在分布式系统中,由于服务数量巨多,为了方便服务配置文件统一管理,实时更新,所以需要分布式配置中心组件.在Spring Cloud中,有分布式配置中心组件spring cloud config ...
- 史上最简单的SpringCloud教程 | 第六篇: 分布式配置中心(Spring Cloud Config)
一.简介 在分布式系统中,由于服务数量巨多,为了方便服务配置文件统一管理,实时更新,所以需要分布式配置中心组件. 在Spring Cloud中,有分布式配置中心组件spring cloud confi ...
- SpringCloud教程 | 第六篇: 分布式配置中心(Spring Cloud Config)(Finchley版本)
在上一篇文章讲述zuul的时候,已经提到过,使用配置服务来保存各个服务的配置文件.它就是Spring Cloud Config. 一.简介 在分布式系统中,由于服务数量巨多,为了方便服务配置文件统一管 ...
- SpringCloud实战之初级入门(三)— spring cloud config搭建git配置中心
目录 1.环境介绍 2.配置中心 2.1 创建工程 2.2 修改配置文件 2.3 在github中加入配置文件 2.3 修改启动文件 3. 访问配置中心 1.环境介绍 上一篇文章中,我们介绍了如何利用 ...
随机推荐
- 使用Angular CLI从蓝本生成代码
第一篇文章是: "使用angular cli生成angular5项目" : http://www.cnblogs.com/cgzl/p/8594571.html 这篇文章主要是讲生 ...
- Hadoop搭建全程
修改配置文件 cd /etc/sysconfig/network-scripts #进入网络配置目录 dir ifcfg* #找到网卡配置文件 ifc ...
- 部署Flask项目到腾讯云服务器CentOS7
部署Flask项目到腾讯云服务器CentOS7 安装git yum install git 安装依赖包 支持SSL传输协议 解压功能 C语言解析XML文档的 安装gdbm数据库 实现自动补全功能 sq ...
- ssh 提示Connection closed by * 的解决方案
使用ssh方式连接linux系统时,发现一直上报这个错误: Connection closed by 192.168.3.71 port 22 刚开始还以为是端口被防火墙禁止了呢,通过关闭和查看,并没 ...
- 笔记:Spring Boot 配置详解
Spring Boot 针对常用的开发场景提供了一系列自动化配置来减少原本复杂而又几乎很少改动的模板配置内容,但是,我们还是需要了解如何在Spring Boot中修改这些自动化的配置,以应对一些特殊场 ...
- Object.prototype.hasOwnProperty与Object.getOwnPropertyNames
Object.prototype.hasOwnProperty() 所有继承了 Object 的对象都会继承到 hasOwnProperty 方法.这个方法可以用来检测一个对象是否含有特定的自身属性: ...
- 多线程——工具类之Semaphore
一.Semaphore功能介绍 Semaphore类相当于线程计数器,在获取Semaphore对象时设定可以产生的线程总数(线程并不是Semaphore类生成的,它只是统计线程的数量),创建Semap ...
- Frequent Value
Frequent Value poj-3368 题目大意:给你n个数的数列,保证它是单调递增的.给你m个询问,每个询问是询问两个节点之间最长的连续的相等的数的长度. 注释:n,m<=100000 ...
- USACO Humble Numbers
USACO Humble Numbers 这题主要是两种做法,第一种是比较常(jian)规(dan)的-------------用pq(priority_queue)维护,每次取堆中最小值(小根堆) ...
- 解决Hystrix Dashboard 一直是Loading ...的情况
Hystrix是什么 Hystrix 能使你的系统在出现依赖服务失效的时候,通过隔离系统所依赖的服务,防止服务级联失败,同时提供失败回退机制,更优雅地应对失效,并使你的系统能更快地从异常中恢复. Hy ...