springboot1.x apollo 更改属性值不起作用。 ConfigurationProperties
2024-10-21 17:43:20
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呢?
最新文章
- 解决mysql too many connections的问题
- javaweb回顾第五篇浅谈会话
- 【POJ】2170 Lattice Animals
- Flex 选项卡加载方式简介
- [置顶] 博客已迁移至ryantang.me
- cygwin 扩展
- Git 介绍
- 彻底理解Javascript原型继承
- c# 【MVC】WebApi通过HttpClient来调用Web Api接口
- tomcat quartz 被触发两次
- pygame-KidsCanCode系列jumpy-part2-加速度与摩擦力
- xcode如何支持8.0以下
- tensorflow serving
- P2221 [HAOI2012]高速公路
- e796. 设置JSlider的方向
- HP G7服务器添加新硬盘
- Python学习笔记 | 关于python数据对象 hashable & unhashable 的理解
- git版本管理之git-ssh 配置和使用
- 个人JS体系整理(三)
- Verilog三线 - 八线译码器