配置中心--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;

}

}

最新文章

  1. Thinkpad 装 centos 7后发热量大处理
  2. angularjs 表单验证(不完整版)
  3. VS2013快捷键大全
  4. JS检测浏览器是否支持HTML5视频播放 (标签<video>) ,
  5. 安卓开发_浅谈ListView(SimpleAdapter数组适配器)
  6. Java的文件读写操作 <转>
  7. JAVA每日一记
  8. vs2010中的快捷键
  9. HDU4614 Vases and Flowers
  10. Bash For Loop Examples
  11. JQ 复制节点
  12. Eclipse知识
  13. Activiti就是这么简单
  14. istio入门(01)istio的优势在哪里?
  15. Java开发笔记(四十二)日历工具的常见应用
  16. formValidator 插件 使用总结
  17. WPF Grid布局
  18. nuxt.js实战之开发环境配置
  19. canvasJS
  20. 关于VS2013下制作和使用静态库和动态库

热门文章

  1. lsyncd+rsync文件实时同步
  2. Vue-cli使用prerender-spa-plugin插件预渲染和配置cdn
  3. mqtt发送消息,消息体为16进制
  4. 【多线程】ConcurrentLinkedQueue 的实现原理
  5. centos下mysql密码修改与远程连接
  6. paper 142:SDM算法--Supervised Descent Method
  7. c++ 获取文件图标,类型名称,属性 SHGetFileInfo
  8. BZOJ 4421: [Cerc2015] Digit Division(思路)
  9. Android 测试点归纳总结
  10. z-index只能用在定位元素上