配置类
@ConfigurationProperties(prefix = "test")
public class TestProperties {
private Map<String, String> map;
public Map<String, String> getMap() {
return map;
}
public void setMap(Map<String, String> map) {
this.map = map;
}
}
配置中心使用的是nacos
先添加配置
test:
map:
a: b
发布后map被更新成{"a": "b"}
然后把配置更改成
test:
map:
c: d
发布后map变成了{"a": "b", "c": "d"}
原先的a->b映射没有删掉,
把映射关系变成字符串自行解析是可以解决的,
想知道在不改变配置结构的情况下有没有什么方法解决这个问题
监听
org.springframework.cloud.endpoint.event.RefreshEvent
事件,在事件回调中清空map, 并设置为较高优先级保证清空操作在刷新前执行