nacos-group / nacos-spring-project

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

[ISSUE #285] Fix 服务端配置修改后,不支持@Value值的动态变更 #285 #286

Closed wuhaoqiang1 closed 5 months ago

wuhaoqiang1 commented 2 years ago

Please do not create a Pull Request without creating an issue first.

285 服务端配置修改后,不支持@Value值的动态变更

What is the purpose of the change

建议作为动态配置中心,服务端修改配置后支持spring注解@Value值的动态更改,目前nacos-spring-context 1.1.1版本只支持到@NacosValue注解

  1. @NacosValue注解的表达式解析较差,不支持如:123${key1}{key2}321等表达式,不如@value
  2. 耦合性太高,后续项目更改动态配置中心,所有使用@NacosValue的地方都需要更改

Brief changelog

2022.4.27更新

Verifying this change

参照监听NacosConfigReceivedEvent事件的NacosValueAnnotationBeanPostProcessor 新增SpringValueAnnotationBeanPostProcessor监听NacosConfigReceivedEvent事件,支持@Value的同步更新

@Value的值的解析使用spring解析使用的StringValueResolver,更贴近于初始化时@Value的解析

已添加部分单元测试,install后,修改服务端值,测试@Value值动态变更通过,测试值 @Value(value = "123${env1:123}${common:not find}321") @Value(value = "${common:not find}") @Value(value = "aa${env1:123}${common:not find}cc")

注解表达式解析器PlaceholderHelper单元测试通过

望参考,谢谢

Follow this checklist to help us incorporate your contribution quickly and easily:

hujun-w-2 commented 2 years ago

ci not pass

CLAassistant commented 1 year ago

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
2 out of 3 committers have signed the CLA.

:white_check_mark: wuhaoqiang1
:white_check_mark: hujun-w-2
:x: realJackSun
You have signed the CLA already but the status is still pending? Let us recheck it.