遇到的问题
Nacos中修改配置将配置的key 的注释,配置未发生变更问题
NacosValueAnnotationBeanPostPorcessor中有,获取key,是获取的所有注解上的值,而values是enviroment中的属性值
当我们注释掉nacos中的属性时,key依然能取到,但是因为注释的原因value无法取到,nacos直接执行continue逻辑跳过此属性的重新赋值
也就导致了最终属性在spring中没有发生变更
public void onApplicationEvent(NacosConfigReceivedEvent event) {
// In to this event receiver, the environment has been updated the
// latest configuration information, pull directly from the environment
// fix issue #142
for (Map.Entry<String, List<NacosValueTarget>> entry : placeholderNacosValueTargetMap
.entrySet()) {
String key = environment.resolvePlaceholders(entry.getKey());
String newValue = environment.getProperty(key);
if (newValue == null) {
continue;
}
List<NacosValueTarget> beanPropertyList = entry.getValue();
for (NacosValueTarget target : beanPropertyList) {
String md5String = MD5Utils.md5Hex(newValue, "UTF-8");
boolean isUpdate = !target.lastMD5.equals(md5String);
if (isUpdate) {
target.updateLastMD5(md5String);
Object evaluatedValue = resolveNotifyValue(target.nacosValueExpr, key, newValue);
if (target.method == null) {
setField(target, evaluatedValue);
}
else {
setMethod(target, evaluatedValue);
}
}
}
}