删除nacos上的配置后,客户端其实读取到的是客户端内存中的配置,nacos将删除的kv变更没有同步到到客户端。所以感官上看到客户端依旧读的是“老的配置”;
3,解决
实现 ApplicationListener类,当有任何RefreshEvent变更的时候,将自己本地配置置空。具体代码如下:
import static java.util.Collections.emptyMap;
import javax.annotation.Resource;
import org.springframework.cloud.endpoint.event.RefreshEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;
/**
-
@author water
-
@desc 修复nacos的bug(删除nacos配置,但是SpringCloud还是能读到)
-
https://github.com/alibaba/nacos/issues/3803)
*/
@Component
public class CleanupRamConfig implements ApplicationListener, Ordered {
@Resource
private MerchantKey merchant