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.环境介绍 上一篇文章中,我们介绍了如何利用 ...
随机推荐
- nicEditors使用方法
//声明初始化富文本框到context中 <div> <textarea id="context" name="context" style= ...
- vc的环境变量配置和缺少mspdb60.dll的解决方法
vc的编译器是cl.exe,我们如果在vc中编译就不用配置环境,但是如果要在任何位置用命令提示符打开编译器cl.exe来编译程序,那么就要配置环境了. 下面我就讲讲vc的环境变量配置和缺少mspdb6 ...
- php 图片合成时文字颜色丢失
最近在做图片合成的时候无意间发现文字颜色丢失了,仔细找了以后才发现原来是因为图片格式的原因 当图片是png图片时文字的颜色就变成了白色的,So.........去你妹的png,用jpg吧! $dest ...
- linq使用字符串参数排序
今天找了半天资料,有两种种方法: 1.把字符串参数变为lambda表达式 2.使用System.Linq.dynamic引用 这里我讲第二种方法 第一步:nuget搜索关键字"dynamic ...
- Java 类文件结构
Java 诞生之时有句著名的宣传口号"Write Once, Run Anywhere.".但是,Java 语言本身不具备跨平台的能力,而是 JVM 提供了跨平台的能力. 事实上, ...
- PHP编程效率的20个要点--PHP技术教程分享
用单引号代替双引号来包含字符串,这样做会更快一些.因为PHP教程会教你在双引号包围的字符串中搜寻变量,单引号则 不会,注意:只有echo能这么做,它是一种可以把多个字符串当作参数的“函数”(译注:兄弟 ...
- spring boot高性能实现二维码扫码登录(中)——Redis版
前言 本打算用CountDownLatch来实现,但有个问题我没有考虑,就是当用户APP没有扫二维码的时候,线程会阻塞5分钟,这反而造成性能的下降.好吧,现在回归传统方式:前端ajax每隔1秒或2秒发 ...
- 【Python】 子进程创建与使用subprocess
subprocess *****本文参考了Vamei大神的http://www.cnblogs.com/vamei/archive/2012/09/23/2698014.html 运用subproce ...
- linux --> 进程和线程
进程和线程 进程(process)和线程(thread)是操作系统的基本概念,下面用一个类比,来解释它们. 1. 计算机的核心是CPU,它承担了所有的计算任务.它就像一座工厂,时刻在运行. 2. 假定 ...
- Redis --> Redis的接口介绍及使用
Redis的接口介绍及使用 Redis是一个远程内存数据库,它不仅性能强劲,而且还具有复制特性以及为解决问题而生的独一无二的数据模型.Redis提供了5种不同类型的数据结构,各式各样的问题都可以很自然 ...