apollo刷新ConfigurationProperties配置类

参考官方文档搜索 3.2.2.3 ConfigurationProperties使用方式

@Configuration
@ConditionalOnClass({
    
    ApolloAutoConfiguration.class,RefreshScope.class})
public class ApolloReFreshAutoConfig implements ApplicationContextAware {
    
    
    Logger log=LoggerFactory.getLogger(ApolloReFreshAutoConfig.class); 
    ApplicationContext applicationContext;
    
    @Autowired
    RefreshScope refreshScope;
    
    @Bean
    public LoggerConfiguration loggerConfiguration() {
    
    
        return new LoggerConfiguration();
    }
    
    public ApolloReFreshAutoConfig(final RefreshScope refreshScope) {
    
    
        this.refreshScope = refreshScope;
    }
    
    @ApolloConfigChangeListener
    private void refresh(ConfigChangeEvent changeEvent) {
    
    
        log.info("Apollo config refresh start");
        this.applicationContext.publishEvent(new EnvironmentChangeEvent(changeEvent.changedKeys()));
        refreshScope.refreshAll();
        log.info("Apollo config refresh end");
        
    }
    
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
    
    
        this.applicationContext=applicationContext;
    }
}

猜你喜欢

转载自blog.csdn.net/a807719447/article/details/112486423