配置中心--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. mysql中级操作

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

  2. An Easy Introduction to CUDA C and C++

    An Easy Introduction to CUDA C and C++ This post is the first in a series on CUDA C and C++, which i ...

  3. enumerate()(Python)

    >>> E=enumerate('spam') >>> E <enumerate object at 0x1021ceca8> >>> ...

  4. Linux安装系统

    服务器与PC 服务器本质上也是以太计算机,相比较家用电脑而言区别如下: 1.服务器更加稳定 2.通常性能比家用机更高 运维工程师的核心职责 保证服务器不间断运行 提升访问效率 保证数据安全 要完成上面 ...

  5. Mybatis基于接口注解配置SQL映射器(一)

    上文已经讲解了基于XML配置的SQL映射器,在XML配置的基础上MyBatis提供了简单的Java注解,使得我们可以不配置XML格式的Mapper文件,也能方便的编写简单的数据库操作代码. Mybat ...

  6. 使用JAVA如何对图片进行格式检查以及安全检查处理

    一.通常情况下,验证一个文件是否图片,可以通过以下三种方式: 1).判断文件的扩展名是否是要求的图片扩展名 这种判断是用得比较多的一种方式,不过这种方式非常的不妥,别人稍微的把一个不是图片的文件的扩展 ...

  7. springboot-redis相关配置整理

    1.pom.xml引入对应数据文件 <dependency> <groupId>org.springframework.boot</groupId> <art ...

  8. 【进阶技术】一篇文章搞掂:Spring高级编程

    本文篇幅较长,建议合理利用右上角目录进行查看(如果没有目录请刷新). 本文基于<Spring5高级编程>一书进行总结和扩展,大家也可以自行研读此书. 十一.任务调度 任务调度主要由三部分组 ...

  9. ARMv8 架构与指令集.学习笔记

    目 录 第1章 ARMv8简介. 3 1.1基础认识. 3 1.2 相关专业名词解释. 3 第2章 Execution State 4 2.1 提供两种Execution State 4 2.2 决定 ...

  10. python主要探索函数

    在数据分析中,Python的主要探索函数 Python中主要用于书探索的是pandas(数据分析)和matplotlib(数据可视化).其中pandas提供了大量的数据探索的工具与数据相关的函数,这些 ...