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