配置中心--Spring cloud Config

通过本次学习,我们应该掌握:

  • Config Server 读取配置文
  • Config Server 从远程 Git 仓库读取配置文
  • 搭建芮可用 Config Server 集群。
  • 使用 Spri ng Cloud Bus 刷新配置。

构建Config Server

构建工程,在这里我们不在赘述,相信大家也会,在这里我们主要说一下,配置与其主要实现方式.

@Component

public class MyFilter extends ZuulFilter

{

private static Logger log=LoggerFactory.getLogger(MyFilter.class);

@Override
public String filterType(){
return Pre_TYPE;
} @Override
public int filterOrder(){
return 0;
} @Override
public boolean shouldFilter(){
return true;
} public Object run(){
RequestContext ctx=RequestContext.getCurrentContext();
HttpServletRequest request=ctx.getRequest("");
Object accessToken=request.getParameter("token");
if(accessToken==null){
log.warn("token is empty");
ctx.setSendZuulResponse(false);
ctx.setResponseStatusCode(401);
try{
ctx.getResponse().write("token is empty");
}catch(Exception e){
return null;
}
}
log.info("ok");
return null;
}

}

@Component

public class MyFilter extends ZuulFilter

{

private static Logger log=LoggerFactory.getLogger(MyFilter.class);

@Override
public String filterType(){
return Pre_TYPE;
} @Override
public int filterOrder(){
return 0;
} @Override
public boolean shouldFilter(){
return true;
} public Object run(){
RequestContext ctx=RequestContext.getCurrentContext();
HttpServletRequest request=ctx.getRequest("");
Object accessToken=request.getParameter("token");
if(accessToken==null){
log.warn("token is empty");
ctx.setSendZuulResponse(false);
ctx.setResponseStatusCode(401);
try{
ctx.getResponse().write("token is empty");
}catch(Exception e){
return null;
}
}
log.info("ok");
return null;
}

}

@SpringBootApplication

@EnableConfigServer

public class ConfigServerApplication

{

public static void main(String[]args){

SpringApplication.run(ConfigServerApplication.class,args);

}

}

application.yml

spring:

cloud:

config:

server:

native:

search-locations:classpath:/shared

profiles:

active:native

application:

name:config-server

server:

port:8769

本地配置文件

server:

port:8762

foo:foo version 1

spring cloud bus--消息总线

spring :

rabbitmq:

host: localhost

port: 5672

username : guest

password : guest

management:

security

enabled : false

@RestController

@RefreshScope

public class ConfigClientApplication

{

@Value("${foo}")

String foo;

@GetMapping(value="/foo")

public String hi(){

return foo;

}

}

配置文件--spring cloud Config的更多相关文章

  1. spring cloud学习(六)Spring Cloud Config

    Spring Cloud Config 参考个人项目 参考个人项目 : (希望大家能给个star~) https://github.com/FunriLy/springcloud-study/tree ...

  2. 微服务深入浅出(8)-- 配置中心Spring Cloud Config

    Config Server从本地读取配置文件 将所有的配置文件统一写带Config Server过程的目录下,Config Server暴露Http API接口,Config Client调用Conf ...

  3. Spring Cloud Config git版

    由于在学习这块内容的时候还不会使用gitHub所以就用了osc的码云 config server POM文件 <dependency> <groupId>org.springf ...

  4. Spring Cloud Config - RSA简介以及使用RSA加密配置文件

    简介 RSA非对称加密有着非常强大的安全性,HTTPS的SSL加密就是使用这种方法进行HTTPS请求加密传输的.因为RSA算法会涉及Private Key和Public Key分别用来加密和解密,所以 ...

  5. spring cloud config搭建说明例子(四)-补充配置文件

    服务端 ConfigServer pom.xml <dependency> <groupId>org.springframework.cloud</groupId> ...

  6. Spring cloud config配置文件加密解密

    Spring cloud config配置文件加密解密 学习了:http://blog.csdn.net/u010475041/article/details/78110349 学习了:<Spr ...

  7. spring cloud config使用mysql存储配置文件

    spring cloud config使用mysql存储配置文件 1.结构图 2.pom.xml: <?xml version="1.0" encoding="UT ...

  8. spring cloud config 配置文件更新

    Spring Cloud Config Server 作为配置中心服务端 拉取配置时更新 git 仓库副本,保证是最新结果 支持数据结构丰富,yml, json, properties 等 配合 eu ...

  9. 使用对称加密来加密Spring Cloud Config配置文件

    补充 使用Spring Cloud Config加密功能需要下载JCE扩展,用于生成无限长度的密文.链接:http://www.oracle.com/technetwork/java/javase/d ...

随机推荐

  1. Web.xml配置详解(转)

    Web.xml配置详解 Posted on 2010-09-02 14:09 chinaifne 阅读(295105) 评论(16) 编辑 收藏 1 定义头和根元素 部署描述符文件就像所有XML文件一 ...

  2. day13 python生成器函数 推导式 生成器

    day13 python   一.生成器     生成器的本质就是迭代器     生成器的特点和迭代器一样. 取值方式和迭代器一样(__next__())     由生成器函数或生成器表达式来创建   ...

  3. HashMap源码浅析

    HashMap源码主要一些属性 //默认的初始化容量(2的n次方) static final int default_inital_capacity = 16; //最大指定容量为2的30次方 sta ...

  4. mysql中级操作

    解析sql执行过程 show VARIABLES like '%profil%' //查看是否开启了剖析 如没开启set profiling=1; 启用 show profiles; set @que ...

  5. Magolor的数据结构作业

    \(CodeForces 706E ~Working routine\) 给出一个矩阵,每次操作交换两个子矩阵,求最后状态. 使用链表存储,每次交换后,影响到的之后矩阵边缘的指针,暴力修改. \(~~ ...

  6. WPF ComboBox 默认选中无效

    在WPF开发当中,我发现ComboBox的默认选中逻辑失效了,仔细查找后发现后台逻辑并没有出现问题. 测试后发现在XAML中,ComBoBox控件的SelectedValue属性需要写在ItemSou ...

  7. Network基础(三):网线的制作、交换机基本命令模式、交换机命令行基本配置、交换机的密码设置

    一.网线的制作 目标: 在常见的计算机网络中,网线主要用来连接计算机与交换机(或宽带路由器).交换机与交换机.交换机与路由器,以及需要连网的其他各种设备.网线的制作与测试是作为网络管理员的一个入门技能 ...

  8. paper 136:ARM ADS集成开发环境的使用(新版)

    [转载]:http://blog.csdn.net/yhmhappy2006/article/details/1673203 ARM ADS集成开发环境的使用 在这里,将介绍ARM开发软件ADS(AR ...

  9. IDEA2019.1.3最新破解方式

    版本2019.1.3 1.下载破解JAR,放入IDEA的bin文件夹中     链接:https://pan.baidu.com/s/1N1BHeJ0-mmFIWbrh5h4k-g     提取码:g ...

  10. 5. zabbix服务端添加fping

    zabbix服务端添加fping 原文链接:http://blog.chinaunix.net/uid-23500957-id-4366928.html fping-3.15.tar.gz 包的路径D ...