上次测试Apollo发现@Value注解获取的值会实时更新,挺好奇的,就研究了一下。
1、AutoUpdateConfigChangeListener监听器的设置
通过@EnableApolloConfig引入ApolloConfigRegistrar
调用了ApolloConfigRegistrarHelper的registerBeanDefinitions,进入该方法
PropertySourcesProcessor 实现了了 BeanFactoryPostProcessor,看其postProcessBeanFactory方法
initializePropertySources实现了讲配置放到Environment中,并保证了高优先级
initializeAutoUpdatePropertiesFeature实现了监听器的设置
2、@Value注解的处理
ApolloProcessor 实现了BeanPostProcesso