Spring Cloud 之 全局配置
在微服务架构中,全局配置的重要性不言而喻。SpringCloud的全局配置存储主要基于 Git 来实现,即配置信息存储在Git服务器,以统一的方式对外提供访问。在使用上分为 ConfigServer和ConfigClient这两个角色。

一. ConfigServer的应用,这也是一个基于SpringBoot和web应用。启动后做为配置服务器对外提供访问。
1. application.properties文件配置
server.port=8888
spring.cloud.config.server.git.uri=https://gitee.com/xxxx/config-repo
spring.cloud.config.server.git.username={帐号}
spring.cloud.config.server.git.password={密码}
2 .pom文件主要内容
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
</dependencies>
3. 启动类
@SpringBootApplication
@EnableConfigServer
public class App
{
public static void main( String[] args )
{
SpringApplication.run(App.class, args) ;
}
}
二. ConfigClient 即配置应用端 , 一般就是具体的要用到全局配置信息的项目
1. bootstrap.yml文件,由于配置统一放在git服务器上,所以各个应用就无需使用 application.yml 或者 application.properties文件
spring:
application:
name: mockservices
cloud:
config:
uri: http://127.0.0.1:8888
label: branch1 // 表示具体应用配置仓库中哪个分支
configClient客户端应用会应用到配置仓库中哪些配置文件由bootstrap.yml文件中的3个配置项决定:
- spring.application.name 它的value决定加载除 application.properties 或 application.yml 之外的配置文件名
- spring.cloud.config.label 决定具体应用配置仓库中哪个分支
- spring.profiles.active 决定加载哪些profile对应的配置
2. 应用配置的代码
@RunWith(SpringRunner.class)
@SpringBootTest(classes = MockApp.class)
public class ConfigTest { @Value("${name}")
private String name ; @Test
public void test() {
System.out.println(name);
} }
3. pom 文件的必要配置
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency> <dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency> </dependencies>
Spring Cloud 之 全局配置的更多相关文章
- Spring Cloud Feign 自定义配置(重试、拦截与错误码处理) 实践
Spring Cloud Feign 自定义配置(重试.拦截与错误码处理) 实践 目录 Spring Cloud Feign 自定义配置(重试.拦截与错误码处理) 实践 引子 FeignClient的 ...
- Spring Cloud Config(配置中心)
每天学习一点点 编程PDF电子书.视频教程免费下载:http://www.shitanlife.com/code 一.简介 Spring Cloud Config为分布式系统中的外部配置提供服务器和客 ...
- spring cloud Eureka client配置(consumer通过Eureka发起对provider的调用)
参考:http://www.ityouknow.com/springcloud/2017/05/12/eureka-provider-constomer.html springboot版本:2.0.3 ...
- spring cloud config将配置存储在数据库中
Spring Cloud Config Server最常见是将配置文件放在本地或者远程Git仓库,放在本地是将将所有的配置文件统一写在Config Server工程目录下,如果需要修改配置,需要重启c ...
- Spring Cloud Config的配置中心获取不到最新配置信息的问题
Spring Cloud Config的配置中心获取不到最新配置信息的问题 http://blog.didispace.com/spring-cloud-tips-config-tmp-clear/
- 跟我学SpringCloud | 第六篇:Spring Cloud Config Github配置中心
SpringCloud系列教程 | 第六篇:Spring Cloud Config Github配置中心 Springboot: 2.1.6.RELEASE SpringCloud: Greenwic ...
- Spring Cloud Config 实现配置中心,看这一篇就够了
Spring Cloud Config 是 Spring Cloud 家族中最早的配置中心,虽然后来又发布了 Consul 可以代替配置中心功能,但是 Config 依然适用于 Spring Clou ...
- 笔记:Spring Cloud Feign Ribbon 配置
由于 Spring Cloud Feign 的客户端负载均衡是通过 Spring Cloud Ribbon 实现的,所以我们可以直接通过配置 Ribbon 的客户端的方式来自定义各个服务客户端调用的参 ...
- 笔记:Spring Cloud Feign Hystrix 配置
在 Spring Cloud Feign 中,除了引入了用户客户端负载均衡的 Spring Cloud Ribbon 之外,还引入了服务保护与容错的工具 Hystrix,默认情况下,Spring Cl ...
随机推荐
- [lodop]css样式after、before添加content内容之前和之后
css样式可以在内容之前和之后加内容.格式是:css类名:before{content:在之前加的内容}css类名:after{content:在之后加的内容}这种写法在LODOP里直接测试是不行的, ...
- 【Leetcode_easy】929. Unique Email Addresses
problem 929. Unique Email Addresses solution: class Solution { public: int numUniqueEmails(vector< ...
- AWS 身份及验证服务(四)
IAM 概述 集中管理访问AWS资源的访问权限和用户身份认证 支持联合访问管理,支持LADP第三方服务 (Identity Provider) 是非区域相关的服务,全局有效 创建用户.组和角色以应用策 ...
- RabbitMQ官方教程五 Topic(GOLANG语言实现)
在上一教程中,我们改进了日志记录系统. 我们没有使用只能进行虚拟广播的fanout交换器,而是使用直接交换器,并有可能选择性地接收日志. 尽管使用直接交换改进了我们的系统,但它仍然存在局限性-它不能基 ...
- 【GStreamer开发】GStreamer播放教程05——色彩平衡
目标 亮度,对比度,色度和饱和度都是常见的视频调节参数,也是GStreamer里面设置色彩平衡的参数.本教程将展示: 如何发现可用的色彩平衡通道 如何改变它们 介绍 <GStreamer基础教程 ...
- Java面试 - 复制引用和复制对象的区别?
复制引用:把原对象的地址赋给了一个新的引用变量,只要其中一个对象的属性发生变化,另一个对象的属性也随之发生变化. 复制对象:把原对象的内容赋给了一个新的对象,其中一个对象的属性发生变化,并不影响另一个 ...
- QT QML之Label, TextField
现在不是去想缺少什么的时候,该想一想凭现有的东西你能做什么.------ 海明威 <老人与海> Label { id: tipLabel width: 120 height: 40 tex ...
- MongoDB 空间定位(点) 与 距离检索
转自: http://blog.csdn.net/flamingsky007/article/details/39208837 基于 MongoDB 2.6 GeoJSON 格式 { "ty ...
- Windows 下配置 ApacheBench (AB) 压力测试
下载 http://httpd.apache.org/download.cgi 我用的是ApacheHaus. 安装服务 1. 打开apache目录下的 conf/httpd.conf,搜索并修改 L ...
- ServiceStack.Redis 连接有密码的Redis问题解决
在ip:port前面加上@用来表示密码,比如password@ip:port <add key="RedisServer" value="123456@127.0. ...