演示如何使用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的更多相关文章

  1. 【SpringCloud】第七篇: 高可用的分布式配置中心(Spring Cloud Config)

    前言: 必需学会SpringBoot基础知识 简介: spring cloud 为开发人员提供了快速构建分布式系统的一些工具,包括配置管理.服务发现.断路器.路由.微代理.事件总线.全局锁.决策竞选. ...

  2. 【SpringCloud】第六篇: 分布式配置中心(Spring Cloud Config)

    前言: 必需学会SpringBoot基础知识 简介: spring cloud 为开发人员提供了快速构建分布式系统的一些工具,包括配置管理.服务发现.断路器.路由.微代理.事件总线.全局锁.决策竞选. ...

  3. 跟我学SpringCloud | 第六篇:Spring Cloud Config Github配置中心

    SpringCloud系列教程 | 第六篇:Spring Cloud Config Github配置中心 Springboot: 2.1.6.RELEASE SpringCloud: Greenwic ...

  4. 微服务SpringCloud之Spring Cloud Config配置中心Git

    微服务以单个接口为颗粒度,一个接口可能就是一个项目,如果每个项目都包含一个配置文件,一个系统可能有几十或上百个小项目组成,那配置文件也会有好多,对后续修改维护也是比较麻烦,就和前面的服务注册一样,服务 ...

  5. SpringCloud(6)分布式配置中心Spring Cloud Config

    1.Spring Cloud Config 简介 在分布式系统中,由于服务数量巨多,为了方便服务配置文件统一管理,实时更新,所以需要分布式配置中心组件.在Spring Cloud中,有分布式配置中心组 ...

  6. SpringCloud教程 | 第六篇: 分布式配置中心(Spring Cloud Config)

    一.简介 在分布式系统中,由于服务数量巨多,为了方便服务配置文件统一管理,实时更新,所以需要分布式配置中心组件.在Spring Cloud中,有分布式配置中心组件spring cloud config ...

  7. 史上最简单的SpringCloud教程 | 第六篇: 分布式配置中心(Spring Cloud Config)

    一.简介 在分布式系统中,由于服务数量巨多,为了方便服务配置文件统一管理,实时更新,所以需要分布式配置中心组件. 在Spring Cloud中,有分布式配置中心组件spring cloud confi ...

  8. SpringCloud教程 | 第六篇: 分布式配置中心(Spring Cloud Config)(Finchley版本)

    在上一篇文章讲述zuul的时候,已经提到过,使用配置服务来保存各个服务的配置文件.它就是Spring Cloud Config. 一.简介 在分布式系统中,由于服务数量巨多,为了方便服务配置文件统一管 ...

  9. SpringCloud实战之初级入门(三)— spring cloud config搭建git配置中心

    目录 1.环境介绍 2.配置中心 2.1 创建工程 2.2 修改配置文件 2.3 在github中加入配置文件 2.3 修改启动文件 3. 访问配置中心 1.环境介绍 上一篇文章中,我们介绍了如何利用 ...

随机推荐

  1. 使用MBROSTool 工具制作本地硬盘多启动盘的方法总结

    前段时间写了一个自用五合一多启动盘分享--分别用来维护娱乐,wifi密码破解,win&mac登陆密码绕过/清除,反馈的同学还是挺多,觉得大家都有这方面的需求,于是再把自己的使用经验总结一下. ...

  2. 怎么用代码制作WordPress的归档页面

    先看看效果,这个是我网站的归档页面:http://www.shenjieblog.com/archives 其实WordPress自带了一个归档的功能,但是只能显示在网页中的某一个部分,但是我想单独制 ...

  3. 走近webpack(3)--图片的处理

    上一章,咱们学了如何用webpack来打包css,压缩js等.这一篇文章咱们来学习一下如何用webpack来处理图片.废话不多说,咱们开始吧. 首先,咱们随便找一张你喜欢的图片放到src/images ...

  4. laravel 原生 sql

    1.插入数据 DB::insert('insert into users (id, name, email, password) values (?, ?, ? , ? )',[1, 'Laravel ...

  5. 【原创】开启PowerShell远程管理

    非域网络,开启PowerShell远程管理,命令如下: 以下操作,PS命令窗口,必须都以管理员省份执行. Step 1: 机器A和B,分别开启PowerShell远程管理服务A = 192.168.3 ...

  6. eclipse打包

  7. npm5 packag-lock.json

    前几天升级了 Node.js v8.0 后,自带的 npm 也升级到了5.0,第一次使用的时候确实惊艳到了:原本重新安装一次模块要十几秒到事情,现在一秒多就搞定了.先不要激动,现在我来大概讲一下 np ...

  8. spring boot 启动问题

    spring boot启动报错误 Thread-2] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.co ...

  9. R语言-文本挖掘

    ---恢复内容开始--- 案例1:对主席的新年致辞进行分词,绘制出词云 掌握jieba分词的用法 1.加载包 library(devtools) library(tm) library(jiebaR) ...

  10. 【BootStrap】 概述 & CSS

    BootStrap BootStrap由Twitter开发,基于HTML,CSS,JS,是一套前端框架.它的特点是对浏览器良好的支持(目前市面上所有流行浏览器都可以),兼容移动设备,以及响应式设计(响 ...