手动刷新客户端配置内容(Spring Cloud Config)

匿名 (未验证) 提交于 2019-12-03 00:13:02
<dependency>   <groupId>org.springframework.boot</groupId>   <artifactId>spring-boot-starter-actuator</artifactId> </dependency>

增加management.endpoints.web.exposure.include=refresh,health,info

spring.application.name=spring-cloud-config-client server.port=9006 spring.cloud.consul.host=127.0.0.1 spring.cloud.consul.port=8500 #设置不需要注册到 consul 中 spring.cloud.consul.discovery.register=false #显示的暴露接入点 management.endpoints.web.exposure.include=refresh,health,info

在使用配置中心的类上添加@RefreshScope注解:

@RestController //刷新触发地址/actuator/refresh @RefreshScope public class ConfigTestController {      //配置信息通过@Value注解读取,配置项用${配置项}读取     @Value("${bluersw.config}")     private String configBluersw;      @RequestMapping("/ConfigTest")     public String ConfigTest(){         return this.configBluersw;     } }

将Git仓库里的配置内容改外Test-5(bluersw.config=Test-5),启动客户端程序(spring-cloud-config-client),刷新客户端页面127.0.0.1:9006/ConfigTest,发现显示内容还是Test-3,然后执行:

curl -X POST http://127.0.0.1:9006/actuat/refresh

再次刷新页面127.0.0.1:9006/ConfigTest,页面内容显示为Test-5,说明客户端程序内的配置信息读取了最新的值。

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!