Configuration file--spring Cloud Config

Source: Internet
Author: User

Configuration Center--spring Cloud Config

Through this study, we should grasp:

    • Config Server reads the configuration text
    • Config Server reads the configuration from a remote Git repository
    • Build Recco with Config Server cluster.
    • Refresh the configuration with Spri ng Cloud Bus.
Building Config Server

Construction project, here we do not repeat, I believe you will also, here we mainly say, configuration and its main implementation way.
@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

Local configuration file
Server
port:8762
Foo:foo version 1

Spring Cloud bus--Message 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;

}

}

Configuration file--spring Cloud Config

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.