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.环境介绍 上一篇文章中,我们介绍了如何利用 ...
随机推荐
- python笔记之异常
异常 內建异常在exceptions模块内,使用dir函数列出模块的内容. 自定义异常类:继承基类Exception. 异常可以使用raise语句引发,可以使用try ... except ... e ...
- 1-1 struts2 基本配置 struts.xml配置文件详解
详见http://www.cnblogs.com/dooor/p/5323716.html 一. struts2工作原理(网友总结,千遍一律) 1 客户端初始化一个指向Servlet容器(例如Tomc ...
- mybatis动态insert,update
1. 动态update UPDATE ui.user_question_section_xref <set> reviewer = #{0}, score = #{1} , last_up ...
- Ubuntu安装Anaconda
安装Anaconda的最简单方法是下载最新的Anaconda安装程序bash脚本,然后运行它. 在Anaconda Downloads页面找到最新版本的Anaconda for Python 3 .当 ...
- Oracle安装11.2.0.4.180116补丁及如何检查数据库安装补丁
最近做了一个安装11.2.0.4.180116补丁的实验,突然想起之前和同事讨论的一个问题:如何检查数据库安装补丁的版本,之前搜到的是去查dba_registry_history,有的说在操作系统中执 ...
- Jmeter 后置处理器 BeanShell_PostProcessor 适用思考
首先摘抄一段官方文档的话: The following BeanShell variables are set up for use by the script: log - (Logger) - c ...
- SQLite3创建数据库的方法
上次刚接触SqlLite,不知道怎么创建数据库,现在做下总结: 界面和MYSQL一样,都是CMD界面,但不是在SQLite.exe中创建数据库: 首先还是说一下cmd下sqlite的使用网上已经很多了 ...
- 解决C盘中的文件不能修改问题
在不能修改的文件右击属性>点击安全>编辑>点击用户>完全控制. 步骤如图: 最后点击确定.
- 如何打包静态库.a文件 iOS
代码调试好了开始打包成sdk,下面是将要打包的FRSDK代码(FRSDK.h暴露在外面有别人调用) 1.创建新工程(Xcode File-New-Project) 2.把下面的红色框的东西移除 3.将 ...
- Java中HashMap底层实现原理(JDK1.8)源码分析
这几天学习了HashMap的底层实现,但是发现好几个版本的,代码不一,而且看了Android包的HashMap和JDK中的HashMap的也不是一样,原来他们没有指定JDK版本,很多文章都是旧版本JD ...