wordpress屏蔽登陆按钮,长沙专业网站优化定制,新网企业邮箱,my77731免费域名查询分布式配置动态刷新
当配置中心中的配置修改之后#xff0c;客户端并不会进行动态的刷新#xff0c;每次修改配置文件之后#xff0c;都需要重启客户端#xff0c;那么如何才能进行动态刷新呢
可以使用RefreshScope注解配合actuator端点进行手动刷新#xff0c;不需要重…分布式配置动态刷新
当配置中心中的配置修改之后客户端并不会进行动态的刷新每次修改配置文件之后都需要重启客户端那么如何才能进行动态刷新呢
可以使用RefreshScope注解配合actuator端点进行手动刷新不需要重启客户端
需要引入依赖
dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-actuator/artifactId
/dependency配置文件配置
# 端点管理
management:endpoints:web:exposure:include: * # 暴露端点*表示全部暴露 刷新需要用到的是refresh端点并在用到配置文件信息的类上增加RefreshScope注解
RestController
RefreshScope
public class TestController {Value(${version})private String version;RequestMapping(/test)public String test(){return version;}
}此时git上的配置文件修改只需要使用post请求调用http://ip:port/actuator/refresh即可刷新配置而不需要重启客户端使用post请求
彩蛋
这里说一个彩蛋我在看spring-cloud-config-client的源码的时候发现一个ConfigClientWatch是用来进行定时轮询读取config-server的配置这个应该是之前老版本实现的
Scheduled(initialDelayString ${spring.cloud.config.watch.initialDelay:180000},fixedDelayString ${spring.cloud.config.watch.delay:500})
public void watchConfigServer()需要配置spring.cloud.config.watch.enabled
Configuration(proxyBeanMethods false)
ConditionalOnClass(ContextRefresher.class)
ConditionalOnBean(ContextRefresher.class)
ConditionalOnProperty(spring.cloud.config.watch.enabled)
protected static class ConfigClientWatchConfiguration {Beanpublic ConfigClientWatch configClientWatch(ContextRefresher contextRefresher) {return new ConfigClientWatch(contextRefresher);}}其内部使用的是ContextRefresher感兴趣的话可以自己去了解一下 https://zhhll.icu/2021/框架/微服务/springcloud/配置中心/springCloudConfig/2.分布式配置动态刷新/