配置文件--spring cloud Config
配置中心--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的更多相关文章
- spring cloud学习(六)Spring Cloud Config
Spring Cloud Config 参考个人项目 参考个人项目 : (希望大家能给个star~) https://github.com/FunriLy/springcloud-study/tree ...
- 微服务深入浅出(8)-- 配置中心Spring Cloud Config
Config Server从本地读取配置文件 将所有的配置文件统一写带Config Server过程的目录下,Config Server暴露Http API接口,Config Client调用Conf ...
- Spring Cloud Config git版
由于在学习这块内容的时候还不会使用gitHub所以就用了osc的码云 config server POM文件 <dependency> <groupId>org.springf ...
- Spring Cloud Config - RSA简介以及使用RSA加密配置文件
简介 RSA非对称加密有着非常强大的安全性,HTTPS的SSL加密就是使用这种方法进行HTTPS请求加密传输的.因为RSA算法会涉及Private Key和Public Key分别用来加密和解密,所以 ...
- spring cloud config搭建说明例子(四)-补充配置文件
服务端 ConfigServer pom.xml <dependency> <groupId>org.springframework.cloud</groupId> ...
- Spring cloud config配置文件加密解密
Spring cloud config配置文件加密解密 学习了:http://blog.csdn.net/u010475041/article/details/78110349 学习了:<Spr ...
- spring cloud config使用mysql存储配置文件
spring cloud config使用mysql存储配置文件 1.结构图 2.pom.xml: <?xml version="1.0" encoding="UT ...
- spring cloud config 配置文件更新
Spring Cloud Config Server 作为配置中心服务端 拉取配置时更新 git 仓库副本,保证是最新结果 支持数据结构丰富,yml, json, properties 等 配合 eu ...
- 使用对称加密来加密Spring Cloud Config配置文件
补充 使用Spring Cloud Config加密功能需要下载JCE扩展,用于生成无限长度的密文.链接:http://www.oracle.com/technetwork/java/javase/d ...
随机推荐
- java中wait()和sleep()的区别
前言 以前只知道一个结论,但是没法理解,现在水平上来了,自己代码中写了一个验证的方法. 1.先上结论:wait()会释放持有的锁,sleep()不会释放持有的锁 2.验证:看代码运行结果. packa ...
- 三、SpringBoot项目探究
1.pom文件 父项目 <parent> <groupId>org.springframework.boot</groupId> <artifactId> ...
- Redis面试题大全含答案
Redis面试题大全含答案 Redis面试题大全含答案 1.什么是Redis?答:Remote Dictionary Server(Redis)是一个开源的使用ANSI C语言编写.支持网络.可基于内 ...
- 浅谈JavaScript原型图与内存模型
js原型详解 1.内存模型: 1.原型是js中非常特殊一个对象,当一个函数(Person)创建之后,会随之就产生一个原型对象 2. 当通过这个函数的构造函数创建了一个具体的对象(p1)之后,在这个具体 ...
- webpack第一节(3)
模块化加载 上一节进行了一个简单的模块化加载,复杂点 新建一个js文件 名为 world.js 依旧在根目录下 在hello.js中引入world.js 模块化加载,world.js是一个模块 引入的 ...
- PHP排序函数:sort()、rsort()、asort()、arsort()、ksort()、krsort()
sort()函数以升序对数组排序.rsort() 函数以降序对数组排序.asort() 函数对数组从低到高进行排序并保持索引关系.arsort() 函数对数组从高到低进行排序并保持索引关系.ksort ...
- 集合类中的Collection接口实现类
今天学习一下集合包里面的内容,常见的有Collection和Map两个接口的实现类Collection中常见的又分为两种: 1.List ,支持放入重复的对象,实现类有arraylist,linked ...
- PyCharm 默认快捷键
1.编辑(Editing) Ctrl + Space 基本的代码完成(类.方法.属性)Ctrl + Alt + Space 快速导入任意类Ctrl + Shift + Enter 语句完 ...
- 1.zabbix编译安装(环境lnmp)
zabbix服务端安装 1.使用脚本安装.脚本内容如下.安装完用http://192.168.159.20/zabbix #!/bin/bash #使用说明,此版本是针对程序安装路径不在/opt/下的 ...
- [NOIP模拟测试31]题解
A.math 考场乱搞拿了95,2333. 考虑裴蜀定理:$ax+by=z$存在整数解,当且仅当$gcd(a,b)|z$. 那么如果某个数能够被拼出来,就必须满足所有$a_i$的$gcd$是它的因子. ...