zoukankan      html  css  js  c++  java
  • 配置文件--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;

    }
    

    }

  • 相关阅读:
    区块链在零售业和银行业的广泛应用
    云存储平台产品浅析
    LINUX操作系统知识:进程与线程详解
    hibernate实现分页
    Hibernate 映射文件的配置 核心文件的配置 一对一 一对多 多对多 hibernate检索策略 Hibernate中session的关闭问题总结
    留言系统项目总结
    jquery 进行dom操作
    数据库 的outfile 备份与还原 视图 事物 触发器 mysql函数和自定义函数
    数据库的子查询、连接查询
    三 级城市,部门,员工,列表联动的问题解决,获取列表的被选中option对象问题
  • 原文地址:https://www.cnblogs.com/dibinbin/p/9267943.html
Copyright © 2011-2022 走看看