Refer to the official documentation to search for 3.2.2.3 ConfigurationProperties usage
@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;
}
}