nacos-group / nacos-spring-project

Nacos ECO Project for Spring Framework
https://nacos.io/
Apache License 2.0
756 stars 311 forks source link

nacos集成springboot2.1.17 配置无法动态更新 #233

Closed sky20086 closed 4 years ago

sky20086 commented 4 years ago

Issue Description

配置无法动态更新,自动更新的配置都已开启

Type: bug report or feature request

通过debug发现nacos服务端有推送新配置到客户端,推送配置的客户端处理进入了如下Listener,但是environment.getPropertySources()取到的是最初的配置值,定位发现,environment从ConfigurationPropertySourcesPropertySource {name='configurationProperties'} 这个配置中先读取到了系统启动时的配置,这个配置是springboot2新增的,会缓存系统启动时的所有配置

NacosPropertySourcePostProcessor.java Listener listener = new AbstractListener() { public void receiveConfigInfo(String config) { String name = nacosPropertySource.getName(); NacosPropertySource newNacosPropertySource = new NacosPropertySource(dataId, groupId, name, config, type); newNacosPropertySource.copy(nacosPropertySource); MutablePropertySources propertySources = environment.getPropertySources(); propertySources.replace(name, newNacosPropertySource); } };

Describe what happened (or what feature you want)

Describe what you expected to happen

希望配置可以动态更新

How to reproduce it (as minimally and precisely as possible)

  1. 依赖nacos-config-spring-boot-starter 0.2.7版本

  2. 开发一个contorller,@NacosValue配置一个变量,设置autoRefreshed=true

  3. 改变nacos上的配置,配置不能更新

Tell us your environment

Anything else we need to know?

sky20086 commented 4 years ago

贴的代码好像不太对,这个更新配置是真的更新成功了的,但是新配置排序在后面,刷新bean的属性的时候,调用的environment.getProperty(key),这个值是从configurationProperties里面读到的,真实的最新的配置值没有被读到。