Nacos监听配置修改

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
@Component
class SampleRunner implements ApplicationRunner {

@Autowired
private NacosConfigManager nacosConfigManager;

@Override
public void run(ApplicationArguments args) throws Exception {
nacosConfigManager.getConfigService().addListener(
/* 配置的 dataId ,groupI*/
"nacos-config-boot-example.yaml", "DEFAULT_GROUP", new Listener() {

/**
* Callback with latest config data.
* @param configInfo latest config data for specific dataId in Nacos
* server
*/
@Override
public void receiveConfigInfo(String configInfo) {
Properties properties = new Properties();
try {
properties.load(new StringReader(configInfo));
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("config changed: " + properties);
}

@Override
public Executor getExecutor() {
return null;
}
});
}

}

本文地址: https://github.com/maxzhao-it/blog/post/d4a65e31/