use of org.springframework.boot.ConfigurableBootstrapContext in project apollo by ctripcorp.
the class ApolloConfigDataLoader method load.
@Override
public ConfigData load(ConfigDataLoaderContext context, ApolloConfigDataResource resource) throws IOException, ConfigDataResourceNotFoundException {
ConfigurableBootstrapContext bootstrapContext = context.getBootstrapContext();
Binder binder = bootstrapContext.get(Binder.class);
BindHandler bindHandler = this.getBindHandler(context);
bootstrapContext.registerIfAbsent(ApolloConfigDataLoaderInitializer.class, InstanceSupplier.from(() -> new ApolloConfigDataLoaderInitializer(this.log, binder, bindHandler, bootstrapContext)));
ApolloConfigDataLoaderInitializer apolloConfigDataLoaderInitializer = bootstrapContext.get(ApolloConfigDataLoaderInitializer.class);
// init apollo client
List<PropertySource<?>> initialPropertySourceList = apolloConfigDataLoaderInitializer.initApolloClient();
// load config
bootstrapContext.registerIfAbsent(ConfigPropertySourceFactory.class, InstanceSupplier.from(() -> SpringInjector.getInstance(ConfigPropertySourceFactory.class)));
ConfigPropertySourceFactory configPropertySourceFactory = bootstrapContext.get(ConfigPropertySourceFactory.class);
String namespace = resource.getNamespace();
Config config = ConfigService.getConfig(namespace);
ConfigPropertySource configPropertySource = configPropertySourceFactory.getConfigPropertySource(namespace, config);
List<PropertySource<?>> propertySourceList = new ArrayList<>();
propertySourceList.add(configPropertySource);
propertySourceList.addAll(initialPropertySourceList);
log.debug(Slf4jLogMessageFormatter.format("apollo client loaded namespace [{}]", namespace));
return new ConfigData(propertySourceList);
}
use of org.springframework.boot.ConfigurableBootstrapContext in project apollo by ctripcorp.
the class ApolloSpringApplicationRegisterListener method onApplicationEvent.
@Override
public void onApplicationEvent(ApplicationStartingEvent event) {
ConfigurableBootstrapContext bootstrapContext = event.getBootstrapContext();
bootstrapContext.registerIfAbsent(SpringApplication.class, InstanceSupplier.of(event.getSpringApplication()));
}
Aggregations