Spring Cloud Config Server
来源:互联网 发布:单片机程序实验流程图 编辑:程序博客网 时间:2024/05/06 12:15
Spring Cloud Config provides server and client-side support for externalized configuration in a distributed system. With the Config Server you have a central place to manage external properties for applications across all environments. The concepts on both client and server map identically to the Spring Environment and PropertySource abstractions, so they fit very well with Spring applications, but can be used with any application running in any language. As an application moves through the deployment pipeline from dev to test and into production you can manage the configuration between those environments and be certain that applications have everything they need to run when they migrate. The default implementation of the server storage backend uses git so it easily supports labelled versions of configuration environments, as well as being accessible to a wide range of tooling for managing the content. It is easy to add alternative implementations and plug them in with Spring configuration.
@EnableConfigServer
package demo;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.EnableAutoConfiguration;import org.springframework.cloud.client.discovery.EnableDiscoveryClient;import org.springframework.cloud.config.server.EnableConfigServer;import org.springframework.context.annotation.Configuration;@Configuration@EnableAutoConfiguration@EnableDiscoveryClient@EnableConfigServerpublic class ConfigServerApplication { public static void main(String[] args) { SpringApplication.run(ConfigServerApplication.class, args); }}
resources目录配置信息
启动ConfigServer
2017-07-05 21:48:25.212 DEBUG 1680 --- [ main] s.c.c.d.h.DiscoveryClientHealthIndicator : Discovery Client has been initialized2017-07-05 21:48:25.286 INFO 1680 --- [ main] o.s.i.endpoint.EventDrivenConsumer : Adding {logging-channel-adapter:_org.springframework.integration.errorLogger} as a subscriber to the 'errorChannel' channel2017-07-05 21:48:25.286 INFO 1680 --- [ main] o.s.i.channel.PublishSubscribeChannel : Channel 'configserver:8888.errorChannel' has 1 subscriber(s).2017-07-05 21:48:25.287 INFO 1680 --- [ main] o.s.i.endpoint.EventDrivenConsumer : started _org.springframework.integration.errorLogger2017-07-05 21:48:25.458 INFO 1680 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8888 (http)2017-07-05 21:48:25.460 INFO 1680 --- [ main] .s.c.n.e.s.EurekaAutoServiceRegistration : Updating port to 88882017-07-05 21:48:25.467 INFO 1680 --- [ main] demo.ConfigServerApplication : Started ConfigServerApplication in 12.164 seconds (JVM running for 12.807)
https://github.com/spring-cloud-samples/config-repo目录下有如下配置文件,
我们通过8888端口获取下logtest的配置:
http://localhost:8888/configserver/logtest
得到返回如下:
{ "name":"configserver", "profiles":[ "logtest" ], "label":"master", "version":"a611374438e75aa1b9808908c57833480944e1a8", "state":null, "propertySources":[ { "name":"https://github.com/spring-cloud-samples/config-repo/configserver.yml", "source":{ "info.description":"configserver" } }, { "name":"https://github.com/spring-cloud-samples/config-repo/application.yml", "source":{ "info.description":"Spring Cloud Samples", "info.url":"https://github.com/spring-cloud-samples", "eureka.client.serviceUrl.defaultZone":"http://localhost:8761/eureka/", "foo":"baz" } } ]}
下面我们创建一个新的Config Client程序,看是否可以正常获取到配置信息:
package hello;import org.springframework.beans.factory.annotation.Value;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.cloud.context.config.annotation.RefreshScope;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;@SpringBootApplication@RestController@RefreshScopepublic class Application { @Value("${logging.level.com.example.foo}") String bar; @RequestMapping("/") String hello() { return "Hello " + bar + "!"; } public static void main(String[] args) { SpringApplication.run(Application.class, args); }}
resources目录配置信息,注意,Config Client 我们使用8889端口,uri是上面Config Server默认暴露的接口地址
server: port: 8889spring: application: name: logtest cloud: config: label:master uri:http//localhost:8888
启动Config Client
2017-07-05 22:00:48.633 INFO 10828 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Located managed bean 'refreshScope': registering with JMX server as MBean [org.springframework.cloud.context.scope.refresh:name=refreshScope,type=RefreshScope]2017-07-05 22:00:48.658 INFO 10828 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Located managed bean 'configurationPropertiesRebinder': registering with JMX server as MBean [org.springframework.cloud.context.properties:name=configurationPropertiesRebinder,context=bf1ec20,type=ConfigurationPropertiesRebinder]2017-07-05 22:00:48.668 INFO 10828 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Located managed bean 'refreshEndpoint': registering with JMX server as MBean [org.springframework.cloud.endpoint:name=refreshEndpoint,type=RefreshEndpoint]2017-07-05 22:00:48.845 INFO 10828 --- [ main] o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase 02017-07-05 22:00:49.166 INFO 10828 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8889 (http)2017-07-05 22:00:49.170 INFO 10828 --- [ main] hello.Application : Started Application in 9.573 seconds (JVM running for 10.034)
我们访问下8889端口
- Spring Cloud Config Server
- spring cloud 之 config-server
- Spring Cloud实战(一)-Spring Cloud Config Server
- spring cloud config server 配置中心
- Spring cloud config server 缓存问题
- 基于mysql的spring cloud config server
- Spring Cloud Config Server 配置总结
- spring cloud:spring cloud config
- spring cloud config server 使用本地配置文件报错
- 开始Spring Cloud Config
- Spring Cloud Config
- 关于spring cloud config
- spring cloud config使用
- Spring Cloud Config
- 开始Spring Cloud Config
- Spring Cloud Config 实践
- Spring Cloud Config
- Spring Cloud Config
- jdbc
- 在ABAQUS中使用多孔介质模型
- 守望先锋--MATLAB图像处理辅助Try2
- 数据储存方式
- 文章标题
- Spring Cloud Config Server
- 百度地图快速解决所有SDK中key验证失败,log显示230错误的问题
- bzoj1864: [Zjoi2006]三色二叉树
- Java设计模式之状态模式
- servlet相关
- 机器人技术(10)AtdRobot读取体感相机XtionProLive教程
- 分析usb驱动框架(usb-skeleton)
- PAT甲级 1018 没有AC,也不想重做这题
- (转)从17家顶级基金退出情况中反思投资机构退出之道