配置中心--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. Linux xargs 命令

    xargs xargs 是给命令传递参数的一个过滤器,也是组合多个命令的一个工具. xargs 可以将管道或标准输入(stdin)数据转换成命令行参数,也能够从文件的输出中读取数据. xargs 也可 ...

  2. 2019年React学习路线图

    作者|javinpaul 译者|无明 之前我们已经介绍了 2019 年 Vue 学习路线图,而 React 作为当前应用最广泛的前端框架,在 Facebook 的支持下,近年来实现了飞越式的发展,我们 ...

  3. Python3.5-20190505-廖老师-自我笔记字典和set

    字典:以键值对的形式存储数据.他就像字典一样,你可以查偏旁,直接跳到500页找到你想要的数据.但是列表就是从第一页开始一个一个的找,找到500页需要的时间很多. 所以字典就是查找速度快,但是所需要的空 ...

  4. org.apache.http.client.HttpClient使用方法

    一.org.apache.commons.httpclient和org.apache.http.client区别(转)   官网说明: http://hc.apache.org/httpclient- ...

  5. 百度链接提交主动推送 c#实现

    说明:此方法适合百度站长,利用此方法可以第一时间将你的原创文章上传到百度,保护你的著作权,也可以帮你的网站进行引流 以下是代码实现: /// <summary>         /// 提 ...

  6. php wordwrap()函数 语法

    php wordwrap()函数 语法 wordwrap()函数怎么用? wordwrap()函数表示按照指定长度对字符串进行折行处理,语法是wordwrap(string,width,break,c ...

  7. SPI总线介绍和裸机编程分析

    一.SPI总线结构 SPI(Serial Peripheral Interface)串行外设接口,是一种高速的,全双工,同步的通信总线.采用主从模式(Master Slave)架构,支持多个slave ...

  8. PHP基础知识总结(二) 数据类型、数组、变量和运算符

    一.PHP是服务器端的脚本语言.在服务器端解析完成后,向前端浏览器发送html. PHP文件的部署位置在:xampp\htdocs文件夹下,当然这个位置可以修改.二.PHP基本语法 1.文件后缀名是p ...

  9. Red Hat Enterprise Linux 7.x新特性

    Red Hat Enterprise Linux 7.x新特性 RHEL7新特性简介 1.      RHEL7目前支持架构 64-bit AMD.64-bit Intel.IBM POWER.IBM ...

  10. kafka ProducerConfig 配置

    kafka-clients : 1.0.1