application.properties 里面的值
server.port=10000
common.name = zhangsan
common.age = 10
Java代码
public static void main(String[] args) throws InterruptedException {
ConfigurableApplicationContext applicationContext = SpringApplication.run(NacosConfigApplication.class, args);
while (true) {
//当动态配置刷新时,会更新到 Enviroment中,因此这里每隔一秒中从Enviroment中获取配置
String userName = applicationContext.getEnvironment().getProperty("common.name");
String userAge = applicationContext.getEnvironment().getProperty("common.age");
System.err.println("common name :" + userName + "; age: " + userAge);
TimeUnit.SECONDS.sleep(3);
}
}
执行结果
common name :zhangsan; age: 10