博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Cngigure和BUS实现远端配置
阅读量:7071 次
发布时间:2019-06-28

本文共 4999 字,大约阅读时间需要 16 分钟。

1 server依赖

4.0.0
org.sselab
configserver
1.0-SNAPSHOT
org.springframework.boot
spring-boot-starter-parent
1.4.0.RELEASE
org.springframework.cloud
spring-cloud-dependencies
Brixton.RELEASE
pom
import
org.springframework.cloud
spring-cloud-starter-config
org.springframework.cloud
spring-cloud-config-server
org.springframework.boot
spring-boot-starter-test
test
org.springframework.boot
spring-boot-maven-plugin

2 server实现

package org.sselab; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.cloud.config.server.EnableConfigServer; /**  * Created by pinker on 2016/10/31.  */ @SpringBootApplication @EnableConfigServer public class application {
public static void main(String[] args) {
new SpringApplicationBuilder(application.class).web(true).run(args); } }
server:   port: 8888 spring:   application:     name: config-server   cloud:     config:       server:         git:           uri: https://git.oschina.net/xd03122049/springboot-config           search-paths: config-repo           username: xd03122049           password: 85523970

3 server结果

 

4 client配置

4.0.0
org.sselab
configclient
1.0-SNAPSHOT
org.springframework.boot
spring-boot-starter-parent
1.4.0.RELEASE
org.springframework.boot
spring-boot-starter-test
test
org.springframework.boot
spring-boot-starter-web
org.springframework.cloud
spring-cloud-starter-config
org.springframework.cloud
spring-cloud-dependencies
Brixton.RELEASE
pom
import
org.springframework.boot
spring-boot-maven-plugin

5 client实现

spring.application.name=pinker spring.cloud.config.profile=dev spring.cloud.config.label=master spring.cloud.config.uri=http://localhost:8888/ server.port=7002
package org.sselab; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; /**  * Created by pinker on 2016/10/31.  */ @SpringBootApplication public class application {
public static void main(String[] args) {
new SpringApplicationBuilder(application.class).web(true).run(args); } }
package org.sselab.controller; import org.springframework.beans.factory.annotation.Value; import org.springframework.cloud.context.config.annotation.RefreshScope; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; /**  * Created by pinker on 2016/10/31.  */ @RefreshScope @RestController public class TestController {
@Value("${from}") private String from; @GetMapping("/from") public String from(){
return this.from; } public void setFrom(String from) {
this.from = from; } public String getFrom() {
return from; } }

6 client 结果

 

然后将server和client都注册到注册中心,略

转载于:https://www.cnblogs.com/xd03122049/p/6018371.html

你可能感兴趣的文章
基于 HTML5 的 WebGL 和 VR 技术的 3D 机房数据中心可视化
查看>>
PHP,JAVA,NET 开发比较
查看>>
平方开根 - 牛顿迭代(板子整理)
查看>>
java string字符拼接符"+"的研究
查看>>
Layui表格编辑【不依赖Layui的动态table加载】
查看>>
HDU2087剪花布条(KMP)
查看>>
NOIP2018普及初赛解析
查看>>
每次访问都生成不一样sessionId
查看>>
解决Cocos2d-x编译错误: 无法打开 源 文件 "extensions/ExtensionExport.h"
查看>>
SqlServer 循环建表、删除表、更新表
查看>>
jQuery中$.extend(true,object1, object2);深拷贝对象
查看>>
圆角和倒角
查看>>
自然语言处理之维特比算法
查看>>
ubuntu12 is not in the sudoers file
查看>>
c# 生成的没用文件
查看>>
Django文件上传
查看>>
zoj 3627(贪心)
查看>>
JS数组
查看>>
ztree复选框
查看>>
[BZOJ1030][JSOI2007]文本生成器(AC自动机+DP)
查看>>