配置中心--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. 调整Winfrom控件WebBrowser的默认浏览器内核版本

    一.问题解析: 今天在调试程序的时候,需要使用C#的客户端远程登录一个Web页面,用到了WebBrowser控件.但是却发现了一件很神奇的事情:当前浏览器使用的内核,可以通过访问下面这个网站获取:ht ...

  2. loadrunner 11安装教程

    见百度经验,大神教程 https://jingyan.baidu.com/article/da1091fb199da7027849d6ff.html

  3. #2560异或和问题 jdfz集训—秦岳

    题目描述 N个数字,要求选择M次,每次从N个数中选出两个数(Ai,Aj)(但不能和之前某次选择相同),此次选择的得分为Ai xor Aj. 求最大得分. 输入格式 第一行包含两个整数N,M 接下来一行 ...

  4. jQuery 实现表格变色效果

    html <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <ti ...

  5. SSD算法的实现

    本文目的:介绍一个超赞的项目--用Keras来实现SSD算法. 本文目录: 0 前言 1 如何训练SSD模型 2 如何评估SSD模型 3 如何微调SSD模型 4 其他注意点 0 前言 我在学习完SSD ...

  6. Jenkins的安装、部署、启动(完整教程)

    测试环境 Linux系统 Centos 7 安装步骤: 1.安装jdk 我安装的是jdk8,此处就不多说了,自己百度哈,很简单 2.安装jenkins 首先依次执行如下三个命令: 2.1.导入镜像: ...

  7. Nacos 常见问题及解决方法

    Nacos 开源至今已有一年,在这一年里,得到了很多用户的支持和反馈.在与社区的交流中,我们发现有一些问题出现的频率比较高,为了能够让用户更快的解决问题,我们总结了这篇常见问题及解决方法,这篇文章后续 ...

  8. JDK 9 发布仅数月,为何在生产环境中却频遭嫌弃?

    千呼万唤始出来,在经历了整整一年的跳票之后,Java 9 终于在 9 月 21 日拨开云雾,露出真正的面目.对众多 Java 程序员来说,这一天无疑是一个重大的日子,首先 Java 开发者们再也不用羡 ...

  9. springmvc缓存 - cache

    前几篇文章已经搭建了一个基本的springmvc demo,现在我们来完善下.    相信大家写程序的时候都接触过缓存的概念,也都知道,数据量大的时候缓存对于提高效率是很显著的.而缓存一般包括前台静态 ...

  10. CentOS 安装MySQL5.7 源码方式安装

    MySQL rpm方式安装:https://www.cnblogs.com/deverz/p/9560403.html 1.卸载已经安装的MySQL yum list installed mysqlr ...