springboot-cloud-6-config

来源:互联网 发布:linux 显示行号的命令 编辑:程序博客网 时间:2024/06/06 06:58

config-server

application.properties

server.port=8005spring.application.name=config-server###git仓库地址spring.cloud.config.server.git.uri= https://github.com/github-ygy/spring_cloud_test####git 相对目录地址  多个,分开spring.cloud.config.server.git.search-paths=cloud-config-repository###github public 不用配置username 和 password#spring.cloud.config.server.git.username =#spring.cloud.config.server.git.password=

application

@SpringBootApplication@EnableConfigServer  //开启config服务public class ConfigMasterApplication {    public static void main(String[] args) {        SpringApplication.run(ConfigMasterApplication.class, args);    }}

输出

http://localhost:8005/test/prd{  "name": "test",  "profiles": [    "prd"  ],  "label": null,  "version": "16610aaf21ae2e0934ec3522009ef993829ec086",  "state": null,  "propertySources": [    {      "name": "https://github.com/github-ygy/spring_cloud_test/cloud-config-repository/test-prd.properties",      "source": {        "from": "git-prd-1.0"      }    }  ]}
http://localhost:8005/test/prd/dev_ygy{  "name": "test",  "profiles": [    "prd"  ],  "label": "dev_ygy",  "version": "0978a00b06877b63a89653bea4ec0ac8df779df9",  "state": null,  "propertySources": [    {      "name": "https://github.com/github-ygy/spring_cloud_test/cloud-config-repository/test-prd.properties",      "source": {        "from": "git-prd-2.0"      }    }  ]}

config-client

bootstrap.properties
#######必须使用bootstrap.properties  使用application.properties 将无法解析@Value属性#######bootstrap.propeties 会优先于application.properties加载server.port=8006####配置中心git仓库 文件名   与<application> 对应spring.application.name = test#####配置中心git仓库 文件名 启动配置文件标识  与<profile> 对应spring.cloud.config.profile = dev####配置中心git仓库分支名    与<lable> 对应spring.cloud.config.label=dev_ygy####配置中心config server地址spring.cloud.config.uri=http://localhost:8005/

controller

@RestControllerpublic class ConfigClientController {    @Value("${from}")    private String from ;    @RequestMapping("/getConfig")    public String getConfig() {        return this.from;    }}

输出

http://localhost:8006/getConfiggit-dev-2.0

config-eureka(整合)

失败响应机制/自动刷新

依赖
        <dependency>            <groupId>org.springframework.cloud</groupId>            <artifactId>spring-cloud-starter-eureka</artifactId>        </dependency>        <dependency>            <groupId>org.springframework.retry</groupId>            <artifactId>spring-retry</artifactId>        </dependency>        <dependency>            <groupId>org.springframework.boot</groupId>            <artifactId>spring-boot-starter-aop</artifactId>        </dependency>
bootstrap.properties
spring.application.name = config-client#######必须使用bootstrap.properties  使用application.properties 将无法解析@Value属性#######bootstrap.propeties 会优先于application.properties加载server.port=8006###eureka管理eureka.client.serviceUrl.defaultZone=http://pear1:9998/eureka/spring.cloud.config.discovery.enabled = true### 失败响应spring.cloud.config.fail-fast=true####引入aop  retry依赖####最大重试次数 默认6次spring.cloud.config.retry.max-attempts= 6####最大重试时间间隔spring.cloud.config.retry.max-interval= 2000#####初始重试间隔 默认1000spring.cloud.config.retry.initial-interval = 1500##### 下一次间隔系数spring.cloud.config.retry.multiplier= 1.2####开启自动刷新  引入actuator 依赖####  感觉有bug  待后续解决 属性注册不成功,将config-server 项目注册为默认 configserver可行。#spring.cloud.config.discovery.serviceid = config-server####关闭授权management.security.enabled=false####配置中心git仓库 文件名   与<application> 对应spring.cloud.config.name = test#####配置中心git仓库 文件名 启动配置文件标识  与<profile> 对应spring.cloud.config.profile = dev####配置中心git仓库分支名    与<lable> 对应spring.cloud.config.label=dev_ygy####配置中心config server地址###spring.cloud.config.uri=http://localhost:8005/
controller
@RestController@RefreshScopepublic class ConfigClientController {    @Value("${from}")    private String from ;    @RequestMapping("/getConfig")    public String getConfig() {        return this.from;    }}
application
@SpringBootApplication@EnableDiscoveryClientpublic class ConfigClientApplication {    public static void main(String[] args) {        SpringApplication.run(ConfigClientApplication.class, args);        //new SpringApplicationBuilder(ConfigClientApplication.class).web(true).run(args);    }}
post请求刷新
public class PostRquest {    public static void main(String[] args) throws Exception {        HttpResponse<String> jsonResponse = Unirest.post("http://localhost:8006/refresh")                .asString();        System.out.println(jsonResponse.getBody());    }}
输出
//http://localhost:8006/getConfiggit-dev-2.0// post request["config.client.version","from"]//http://localhost:8006/getConfiggit-dev-2.0-refresh
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 真空杯不保温了怎么办 锅底外面烧黑了怎么办 锅底里面烧黑了怎么办 佳能50镜头跑焦怎么办 g7x镜头进灰了怎么办 leica镜头进灰了怎么办 请问喉咙痒咳嗽该怎么办 喉咙痒咳嗽有痰怎么办 痒咳嗽停不下来怎么办 嗓子疼咳嗽有痰怎么办 上火了喉咙干痒怎么办 喉咙里总是有痰怎么办 1岁宝宝喉咙有痰怎么办 嗓子总感觉有痰怎么办 嗓子痒感觉有痰怎么办 1岁宝宝嗓子有痰怎么办 3岁宝宝嗓子有痰怎么办 喉咙总感觉有痰怎么办 感冒了喉咙有痰怎么办 咽喉有异物感是怎么办 老感觉喉咙有痰怎么办 感冒有痰怎么办最有效 感冒快好了有痰怎么办 喉咙里一直有痰怎么办 一到晚上就咳嗽怎么办 1岁宝宝咳嗽痰多怎么办 3岁宝宝咳嗽痰多怎么办 六岁儿童咳嗽有痰怎么办 很多白痰在喉咙怎么办 我喉咙总是有痰怎么办 喉咙老感觉有痰怎么办 喉咙痒老是有痰怎么办 抽烟多了嗓子疼怎么办 抽烟多了老咳嗽怎么办 抽烟抽多了咳嗽怎么办 嗓子咳出异物臭怎么办 鼻子有鼻涕喉咙有痰怎么办 怀孕39周感冒了怎么办 一口痰卡在喉咙怎么办 鼻塞黄鼻涕黄痰怎么办 小孩咳嗽流黄鼻涕怎么办