Skip to content

izachwei/apollo-config-spring-boot-starter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 

Repository files navigation

一个基于 SpringBoot 的 Apollo Config Starter

apollo-config-spring-boot-starter

介绍

用于解决 Apollo 配置中心使用 @ConfigurationProperties 时无法实时更新配置。

使用说明

  • 引入依赖
<dependency>
    <groupId>io.github.izachwei</groupId>
    <artifactId>apollo-config-spring-boot-starter</artifactId>
    <version>1.0.4-RELEASE</version>
</dependency>
  • 在 @ConfigurationProperties bean 上添加注解 @ApolloConfigRefresh,开启配置热更新。

原理

  1. 利用BeanPostProcessor后置处理器收集打上@ApolloConfigRefresh的配置类,缓存在apolloConfigCache(key:prefix,value: beanName)
  2. @ApolloConfigChangeListener 监听 Apollo 配置的变更,通过 apolloConfigCache 获取对应的bean,最后使用refreshScope.refresh()刷新配置bean。
apollo update key -> ApolloConfigChangeListener -> apolloConfigCache.get(configKey) -> refreshScope.refresh()