springcloud的config更新配置
2017-11-26 23:32
288 查看
在config的client端需要更新变量的对应的controller加入注解
@RefreshScope
在配置文件里加入配置
management.security.enabled=false
配置成功,启动程序,通过postman调用refresh来刷新配置
http://localhost:8081/refresh
@RefreshScope
package com.lyq.controller; import org.springframework.beans.factory.annotation.Value; import org.springframework.cloud.context.config.annotation.RefreshScope; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; /** * Created by 云强 on 2017/11/21. */ @RestController // 在执行refresh时会刷新bean中变量值 @RefreshScope public class ConfigTestController { @Value("${foo}") String foo; @RequestMapping(value = "/config/hi") public String hi(){ return foo; } }
在配置文件里加入配置
management.security.enabled=false
spring.application.name=service-demo #关闭thymeleaf的缓存,不然在开发过程中修改页面不会立刻生效需要重启,生产可配置为true。 spring.thymeleaf.cache=false #注册eureka服务 eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/ server.port=8081 #config客户端配置 spring.cloud.config.label=master spring.cloud.config.profile=dev #spring.cloud.config.uri=http://localhost:8888/ spring.cloud.config.discovery.enabled=true spring.cloud.config.discovery.serviceId=config-server #springboot 1.5.X 以上默认开通了安全认证,所以需要在配置文件application.properties添加以下配置,以post请求的方式来访问http://localhost:8081/refresh 就会更新修改后的配置文件 management.security.enabled=false
配置成功,启动程序,通过postman调用refresh来刷新配置
http://localhost:8081/refresh
相关文章推荐
- 史上最简单的SpringCloud教程 | 第七篇: 高可用的分布式配置中心(Spring Cloud Config)
- SpringCloud教程 | 第六篇: 分布式配置中心(Spring Cloud Config)(Finchley版本)
- springcloud config 分布式配置中心
- springcloud学习笔记(十一) 高可用的分布式配置中心(Spring Cloud Config)
- Spring Cloud Config实现分布式配置中心
- Spring Cloud Config Client配置说明
- Spring Cloud(十)高可用的分布式配置中心 Spring Cloud Config 中使用 Refresh
- 第六篇: 分布式配置中心(Spring Cloud Config)
- 第六篇: 分布式配置中心(Spring Cloud Config)
- 第七篇: 高可用的分布式配置中心(Spring Cloud Config)
- 史上最简单的SpringCloud教程 | 第六篇: 分布式配置中心(Spring Cloud Config)
- Spring Cloud Config采用数据库存储配置内容【Edgware+】
- (Spring Cloud微服务实战-书中之坑)spring cloud config优先读取本地配置,其次读取git仓库
- SpringCloud之分布式服务配置中心(Spring Cloud Config)
- Spring Cloud Config Server 配置说明
- 史上最简单的SpringCloud教程 | 第六篇: 分布式配置中心(Spring Cloud Config)
- 第六篇: 分布式配置中心(Spring Cloud Config)
- 第七篇: 高可用的分布式配置中心(Spring Cloud Config)
- 第七篇: 高可用的分布式配置中心(Spring Cloud Config)
- spring cloud config server 配置中心