nacos-group / nacos-examples

Nacos Examples
Apache License 2.0
950 stars 1.47k forks source link

诡异的没有使用到bootstrap.properties中config.shared-configs[0].refresh=true配置? #84

Closed xhans closed 2 years ago

xhans commented 2 years ago

版本信息 spring-boot:2.6.3 spring-cloud:2021.0.3 jdk:1.8 nacos-config:2.2.0.RELEASE nacos-server:2.1.0(单机)

配置 bootstrap.properties中使用shared-config指定了额外的配置文件,如下: spring.cloud.nacos.config.file-extension=properties spring.cloud.nacos.config.shared-configs[0]=safe.properties spring.cloud.nacos.config.shared-configs[0].group=DEFAULT_GROUP spring.cloud.nacos.config.shared-configs[0].refresh=true

问题 修改safe.properties配置文件内容后,没有动态获取到修改后的值? image

尝试解决问题 项目启动后在org.springframework.cloud.context.refresh.ContextRefresher的refresh 方法设置断点后,继续更新safe.properties文件内容,重新发布,没有进入断点。

项目启动时在com.alibaba.cloud.nacos.NacosConfigProperties的sharedConfigs方法设置断点,此时safe.properties文件的refresh属性为false image

项目启动时在com.alibaba.cloud.nacos.NacosConfigProperties的assembleConfigServiceProperties方法设置断点,此方法返回的Properties对象中有键值对:"sharedConfigs[0].refresh"->"true",该处说明配置已被读取。然而断点观察发现Properties对象在创建出ConfigService对象后,后续没有在使用?

image

image 观察到好像没有使用Properties对象的值去更新NacosConfigProperties对象中的sharedConfigs属性中对应的refresh的值。后续流程中一直使用NacosConfigProperties对象中默认的false值? image