配置文件--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 ...
随机推荐
- sublime text的快捷键
Ctrl + Shift + P:调出命令板(Command Palette)Ctrl + `:调出控制台Ctrl + Enter:在当前行下面新增一行然后跳至该行Ctrl + Shift + Ent ...
- JavaScript 下载大文件解决方案(Blob+OjbectURL)
结合Blob和OjbectURL实现更大的文件下载: var a = document.createElement('a'); var txt = '.....content....'; for(va ...
- MAVEN项目标准目录结构(转)
转自:http://blog.csdn.net/lengyue_wy/article/details/6718637 版权声明:本文为博主原创文章,未经博主允许不得转载. 1.标准目录结构: s ...
- java中wait()和sleep()的区别
前言 以前只知道一个结论,但是没法理解,现在水平上来了,自己代码中写了一个验证的方法. 1.先上结论:wait()会释放持有的锁,sleep()不会释放持有的锁 2.验证:看代码运行结果. packa ...
- 【leetcode】435. Non-overlapping Intervals
题目如下: Given a collection of intervals, find the minimum number of intervals you need to remove to ma ...
- C/C++ C++ 11 std::move()
{ 0. C++ 标准库使用比如vector::push_back 等这类函数时,会对参数的对象进行复制,连数据也会复制.这就会造成对象内存的额外创建, 本来原意 是想把参数push_back进去就行 ...
- hdu 6092 Rikka with Subset (集合计数,01背包)
Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he ...
- 【Flutter学习】页面布局之基础布局组件
一,概述 Flutter中拥有30多种预定义的布局widget,常用的有Container.Padding.Center.Flex.Row.Colum.ListView.GridView.按照< ...
- 工程师技术(四):配置SMB文件夹共享、多用户Samba挂载、普通NFS共享的实现、安全NFS共享的实现
一.配置SMB文件夹共享 目标: 本例要求在虚拟机 server0 上发布两个共享文件夹,具体要求如下: 1> 此服务器必须是 STAFF 工作组的一个成员 2> 发布目录 /comm ...
- MFC不同窗口之间传递数据
问题的由来: 最近在学习串口通信编程,参考的例子大多数都是在一个对话框中同时完成对串口的配置及数据收发的功能.这种方式不太适合于写自己的应用程序(会使得程序界面比较混乱,无法突出程序的重点),因此想让 ...