重写spring cloud config 本地bootstrap
spring.application.name=ms-asset
spring.cloud.config.label=master
spring.cloud.config.profile=test
spring.cloud.config.uri=http://ms-config-server-srv:8001/
-Dspring.cloud.config.label=master
-Dspring.cloud.config.profile=test
public ConfigClientProperties override(
org.springframework.core.env.Environment environment) {
ConfigClientProperties override = new ConfigClientProperties();
BeanUtils.copyProperties(this, override);
override.setName(
environment.resolvePlaceholders("${" + ConfigClientProperties.PREFIX
+ ".name:${spring.application.name:application}}"));
if (environment.containsProperty(ConfigClientProperties.PREFIX + ".profile")) {
override.setProfile(
environment.getProperty(ConfigClientProperties.PREFIX + ".profile"));
}
if (environment.containsProperty(ConfigClientProperties.PREFIX + ".label")) {
override.setLabel(
environment.getProperty(ConfigClientProperties.PREFIX + ".label"));
}
return override;
}
package com.example; import org.springframework.boot.context.event.ApplicationPreparedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.core.env.CompositePropertySource;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.PropertySource; @Component
@Order(Ordered.HIGHEST_PRECEDENCE)
public class ConfigServicePropertyDeprioritizer
implements ApplicationListener<ApplicationPreparedEvent>
{
private static final String CONFIG_SOURCE = "bootstrap"; private static final String PRIORITY_SOURCE = "systemEnvironment"; @Override
public void onApplicationEvent(ApplicationPreparedEvent event)
{
ConfigurableEnvironment environment = event.getApplicationContext()
.getEnvironment();
MutablePropertySources sources = environment.getPropertySources();
PropertySource<?> bootstrap = findSourceToMove(sources); if (bootstrap != null)
{
sources.addAfter(PRIORITY_SOURCE, bootstrap);
}
} private PropertySource<?> findSourceToMove(MutablePropertySources sources)
{
boolean foundPrioritySource = false; for (PropertySource<?> source : sources)
{
if (PRIORITY_SOURCE.equals(source.getName()))
{
foundPrioritySource = true;
continue;
} if (CONFIG_SOURCE.equals(source.getName()))
{
// during bootstrapping, the "bootstrap" PropertySource
// is a simple MapPropertySource, which we don't want to
// use, as it's eventually removed. The real values will
// be in a CompositePropertySource
if (source instanceof CompositePropertySource)
{
return foundPrioritySource ? null : source;
}
}
} return null;
}
}
重写spring cloud config 本地bootstrap的更多相关文章
- spring cloud config的bootstrap.yml与application.proterties的区别
bootstrap.yml 和application.yml 都可以用来配置参数 bootstrap.yml可以理解成系统级别的一些参数配置,这些参数一般是不会变动的 application.ym ...
- Spring Cloud官方文档中文版-Spring Cloud Config(下)-客户端等
官方文档地址为:http://cloud.spring.io/spring-cloud-static/Dalston.SR2/#_serving_alternative_formats 文中例子我做了 ...
- Spring Cloud Config中文文档
https://springcloud.cc/spring-cloud-config.html 目录 快速开始 客户端使用 Spring Cloud Config服务器 环境库 健康指标 安全 加密和 ...
- spring cloud config配置
参考: http://www.ityouknow.com/springcloud/2017/05/22/springcloud-config-git.html http://www.ityouknow ...
- spring cloud config —— git配置管理
目录 talk is cheep, show your the code Server端 pom.xml server的application.yml 配置文件 测试Server client端 po ...
- Spring Cloud Config入门(本地配置)
spring cloud config 简介 Spring Cloud Config为分布式系统中的外部化配置提供服务器和客户端支持.使用Config Server,您可以在所有环境中管理应用程序的外 ...
- spring cloud --- config 配置中心 [本地、git获取配置文件]
spring boot 1.5.9.RELEASE spring cloud Dalston.SR1 1.前言 spring cloud config 配置中心是什么? 为了统一管理配 ...
- Spring Cloud官方文档中文版-Spring Cloud Config(上)
官方文档地址为:http://cloud.spring.io/spring-cloud-static/Dalston.SR2/#spring-cloud-feign 文中例子我做了一些测试在:http ...
- Spring Cloud Config - RSA简介以及使用RSA加密配置文件
简介 RSA非对称加密有着非常强大的安全性,HTTPS的SSL加密就是使用这种方法进行HTTPS请求加密传输的.因为RSA算法会涉及Private Key和Public Key分别用来加密和解密,所以 ...
随机推荐
- React事件系统入门
React基于虚拟DOM实现了一个合成事件层,我们所定义的事件处理器会接受到一个合成事件层对象的实例,它完全符合W3C标准,不会存在任何IE标准的兼容性问题.并且和原生的浏览器事件一样拥有同样的接口, ...
- Codeforces Round #127 (Div. 1) E. Thoroughly Bureaucratic Organization 二分 数学
E. Thoroughly Bureaucratic Organization 题目连接: http://www.codeforces.com/contest/201/problem/E Descri ...
- SNAT的作用是什么
SNAT,可能有人觉得奇怪,好好的为什么要进行ip地址转换啊,为了弄懂这个问题,我们要看一下局域网用户上公网的原理,假设内网主机A(192.168.2.8)要和外网主机B(61.132.62.131) ...
- 【Tomcat】Tomcat闪退的问题解决/Tomcat修改端口号无效
一. Tomcat闪退的问题解决 1.首先 确定JDK的环境变量配置正确 2.下载纯净的新的Tomcat 3.在bin\startup.bat文件中的第一行前面加入: SET JAVA_HOME = ...
- 【架构】Nginx如何设置X-Request-ID请求头,记录请求时间:毫秒?
Nginx is awesome, but it’s missing some common features. For instance, a common thing to add to acce ...
- 用java源代码学数据结构<七>: BST
/* * 以int类为例 * 其它的类必须能够比较 * */ //二叉搜索树的节点点 class BSTNode{ int item; BSTNode lc; BSTNode rc; BSTNode ...
- .NET-DataColumn.DataType 属性
public DataTable MakeDataTable(){ DataTable myTable; DataRow myNewRow; // Create a new DataTable. my ...
- java 注解(自身理解)
声明注解 使用注解 解析注解 产生的结果 注解利用的是反射机制 ============================================================= 使用注解修饰 ...
- TreeView 类 事件
名称 说明 AfterCheck 在选中树节点复选框后发生. AfterCollapse 在折叠树节点后发生. AfterExpand 在展开树节点后发生. AfterLabelEdit 在编辑树节点 ...
- 元素的数据存储-jQuery.data()与.data()
jQuery提供的存储接口 jQuery.data( element, key, value ) //静态接口,存数据 jQuery.data( element, key ) //静态接口,取数据 . ...