Nacos 自动更新配置不生效问题
版本
Nacos 1.4.1
SpringCloud 2020.0.3
解决方案
bootstrap.properties 增加应用名配置即可
spring.application.name=service-product
(导致失效的原因可能有多种,如果上述解决方案无效,可以评论私信我具体版本)
自动更新原理
其实是借助spring重新加载配置的能力,当Nacos发现配置文件MD5不一致时,新增刷新事件,触发SpringCloud重新加载逻辑。
com.alibaba.nacos.api.config.listener.AbstractSharedListener#innerReceive 发布Refesh事件
public void innerReceive(String dataId, String group,
String configInfo) {
refreshCountIncrement();
nacosRefreshHistory.addRefreshRecord(dataId, group, configInfo);
// todo feature: support single refresh for listening
applicationContext.publishEvent(
new RefreshEvent(this, null, "Refresh Nacos config"));
if (log.isDebugEnabled()) {
log.debug(String.format(
"Refresh Nacos config group=%s,dataId=%s,configInfo=%s",
group, dataId, configInfo));
}
}
org.springframework.cloud.endpoint.event.RefreshEventListener#handle(org.springframework.cloud.endpoint.event.RefreshEvent) SpringApplication调用刷新入口
public void handle(RefreshEvent event) {
if (this.ready.get()) { // don't handle events before app is ready
log.debug("Event received " + event.getEventDesc());
Set<String> keys = this.refresh.refresh();
log.info("Refresh keys changed: " + keys);
}
}
org.springframework.boot.SpringApplication#applyInitializers 获取初始化类 如下
org.springframework.cloud.bootstrap.BootstrapApplicationListener$AncestorInitializer@1491c218
org.springframework.cloud.bootstrap.BootstrapApplicationListener$DelegatingEnvironmentDecryptApplicationInitializer@1a06e969
org.springframework.cloud.bootstrap.config.PropertySourceBootstrapConfiguration@1d443173 //Nacos的配置加载locate注册在这
org.springframework.cloud.bootstrap.encrypt.EnvironmentDecryptApplicationInitializer@6a729f71
org.springframework.boot.context.config.DelegatingApplicationContextInitializer@57ced7d3
org.springframework.boot.autoconfigure.SharedMetadataReaderFactoryContextInitializer@6a2234f6
org.springframework.boot.context.ContextIdApplicationContextInitializer@7a9fa37c
org.springframework.boot.context.ConfigurationWarningsApplicationContextInitializer@35cd7790
org.springframework.boot.rsocket.context.RSocketPortInfoApplicationContextInitializer@141c4eb5
org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer@6fe25d44
org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportLoggingListener@68618787
com.alibaba.cloud.nacos.client.NacosPropertySourceLocator#locate 这里获取应用名 只能获取到bootstrap中配置的
原因是springCloud正常启动时会先加载application.yml,而刷新配置时不会
String dataIdPrefix = nacosConfigProperties.getPrefix();
if (StringUtils.isEmpty(dataIdPrefix)) {
dataIdPrefix = name;
}
if (StringUtils.isEmpty(dataIdPrefix)) {
dataIdPrefix = env.getProperty("spring.application.name");
}
com.alibaba.nacos.api.config.ConfigService#getConfig 这个是真正获取配置的接口
Nacos 自动更新配置不生效问题的更多相关文章
- Spring Cloud Bus 自动更新配置
---恢复内容开始--- Spring Cloud Config 结合 Spring Cloud bus 实现 git 仓库提交配置文件 触发消息队列 应用自动更新配置 1. config 服务端 添 ...
- SpringBoot整合Nacos自动刷新配置
目的 Nacos作为SpringBoot服务的注册中心和配置中心. 在NacosServer中修改配置文件,在SpringBoot不重启的情况下,获取到修改的内容. 本例将在配置文件中配置一个 cml ...
- 带你入门SpringCloud 之 通过SpringCloud Bus 自动更新配置
前言 在<带你入门SpringCloud统一配置 | SpringCloud Config>中通过 SpringCloud Config 完成了统一配置基础环境搭建,但是并没有实现配置修改 ...
- webpack-dev-server的自动更新配置
一.背景 测试发布一个项目,修改jsx中的内容,页面不自动更新. 每次必须执行npm run build:然后执行npm run start. 脚本如下: "scripts": { ...
- Spring Cloud Bus实现自动更新配置
一.概述 1. 配置环境 版本:Spring Boot版本2.0.3.RELEASE,Spring Cloud版本Finchley.SR1,RabbitMQ 3.7.7 说明:本文章是在https:/ ...
- spring cloud学习(六) 配置中心-自动更新
上一篇学习了spring cloud config的基本使用,但发现有个问题,就是每次更改配置后,都需要重启服务才能更新配置,这样肯定是不行的.在上网查资料了解后,spring cloud支持通过AM ...
- SVN的基本原理 配置自动更新WEB服务器
SVN的基本原理 配置自动更新WEB服务器 最近有个小项目,需要用SVN来进行版本控制.项目组的同僚有8个人,大家都在本地开发,然后提交到服务器——服务器就是其中一台机器.专门安排一个测试员来进行项目 ...
- Spring Cloud 整合 nacos 实现动态配置中心
上一篇文章讲解了Spring Cloud 整合 nacos 实现服务注册与发现,nacos除了有服务注册与发现的功能,还有提供动态配置服务的功能.本文主要讲解Spring Cloud 整合nacos实 ...
- linux小白成长之路4————centos7配置自动更新安装安全补丁
[内容指引] 安装yum-cron; 修改配置:nano: 手工启动服务: 将服务设置为开机自动启动. 为保证linux系统的安全性以及稳定性,可以使用yum-cron服务自动更新: 1.安装yum- ...
随机推荐
- vivo商城促销系统架构设计与实践-概览篇
一.前言 随着商城业务渠道不断扩展,促销玩法不断增多,原商城v2.0架构已经无法满足不断增加的活动玩法,需要进行促销系统的独立建设,与商城解耦,提供纯粹的商城营销活动玩法支撑能力. 我们将分系列来介绍 ...
- npm 操作代码
npm cache clean -force //强制清除缓,比如安装echarts失败后,清除,在安装
- base64的实现原理
base64是处理二进制数据的一种编码方式,可用于把二进制数据编码成64个可打印的字符. 学习base64之前,先了解一下什么是字节与编码 什么是字节 互联网中的数据都是用字节来表示的,一个字节有8位 ...
- 3.QT屏幕分辨率适配
需求:qt的窗口.组件.字体需要适配屏幕分辨率. 思路:qt是根据显示器的物理长度或者宽度于分辨率的关系来计算dpi 实现: #if(QT_VERSION >= QT_VERSION_CHECK ...
- MySQL数据库复制技术应用实战(阶段二)
MySQL数据库复制技术应用实战(阶段二)文档 作者 刘畅 时间 2020-9-27 服务器版本:CentOS Linux release 7.5.1804 主机名 ip地址 服务器配置 安装软件 密 ...
- 其他:Spring5.0框架源码导入IDEA
1.下载Spring spring-framework-5.0.4.RELEASE下载地址:https://github.com/spring-projects/spring-framework/re ...
- Spring 依赖注入(DI) 的三种方式 和 对集合类型的注入
// 分别省略了getter setter public class Student { private String name; private int age; private Teacher t ...
- so层反调试方法以及部分反反调试的方法
1.检测ida远程调试所占的常用端口23946,是否被占用 //检测idaserver是否占用了23946端口 void CheckPort23946ByTcp() { FILE* pfile=NUL ...
- Word转PDF的VBA脚本
将以下内容复制粘贴在一个txt中,修改txt后缀为".vbs" On Error Resume Next Const wdExportFormatPDF = 17 Set oWor ...
- ctf之SusCTF2017-Crack Zip
题目信息如下,可知为杂项题,且无提示 下载文件打开如图,该压缩包是加密的 首先想到的是暴力破解,下载zip暴力破解软件打开文件. 下一步,选择暴力破解 进行暴力破解设定,进行破解 破解完成,得到密解压 ...