1. @ApolloConfigChangeListeners 默认监控命名空间是 application.properties , 如果是自己创建的namespace ,一定要明确指定(包含文件扩展名)。

 @ApolloConfigChangeListener(value = {"xx.yml"})
public void onChange(ConfigChangeEvent configChangeEvent) {
ConfigChange change;
System.out.println("Xxx");
}
同理如果使用手动方式注册监听器的时候也 应明确指定命名空间。(同样注意一定加上文件扩展名)
ConfigChangeListener configChangeListener = new ConfigChangeListener() {
@Override
public void onChange(ConfigChangeEvent configChangeEvent) {
ConfigChange change;
System.out.println("Xxx");
}
};
ConfigService.getConfig("xx.yml").addChangeListener(configChangeListener);
注意这里的getConfig ,还有一个getAppConfig 还有一个 getConfigFile 。 其中前两个对应的监听执行器是AbstractConfig , 后一个是 AbstractConfigFile 。
这三个方法, 其中 getAppCofnig是指默认默认空间 application ,但是调试发现其参数是不带文件扩展名称的。
public static Config getAppConfig() {
return getConfig(ConfigConsts.NAMESPACE_APPLICATION);
}
String NAMESPACE_APPLICATION = "application";
为什么我使用getConfig,其入参也是namespace ,为什么我传入参数时 必须加上扩展名称呢???(不加的时候,数据发生变化时,根本就不调用你定义的监听器,搞了半天。)
public static Config getConfig(String namespace) {
return s_instance.getManager().getConfig(namespace);
}
还有一个getConfigFile 这个是监听整个配置文件的,文件变更即调用,但是请求值是整个文件,需要自己对比哪些值发生变化。

问题: getConfig()监控的yml 文件,我是对应的bean @ConfigurationProperties("defines") . 如何将这个变化同步到bean呢?



最新文章

  1. 解决mysql too many connections的问题
  2. javaweb回顾第五篇浅谈会话
  3. 【POJ】2170 Lattice Animals
  4. Flex 选项卡加载方式简介
  5. [置顶] 博客已迁移至ryantang.me
  6. cygwin 扩展
  7. Git 介绍
  8. 彻底理解Javascript原型继承
  9. c# 【MVC】WebApi通过HttpClient来调用Web Api接口
  10. tomcat quartz 被触发两次
  11. pygame-KidsCanCode系列jumpy-part2-加速度与摩擦力
  12. xcode如何支持8.0以下
  13. tensorflow serving
  14. P2221 [HAOI2012]高速公路
  15. e796. 设置JSlider的方向
  16. HP G7服务器添加新硬盘
  17. Python学习笔记 | 关于python数据对象 hashable & unhashable 的理解
  18. git版本管理之git-ssh 配置和使用
  19. 个人JS体系整理(三)
  20. Verilog三线 - 八线译码器

热门文章

  1. codeforce C. Maximal Intersection
  2. Windows10使用VMware安装centos
  3. Spring全家桶(一)之Spring总结
  4. Windows11使用WSL Ubuntu搭建paddle的GPU环境
  5. SpringBoot Circular view path错误
  6. [iOS]Universal Link
  7. Object.create() 方浅析
  8. scrum和SAFe
  9. git 问题解决
  10. vscode 终端中运行执行js文件