use of com.ctrip.framework.apollo.Config in project apollo by ctripcorp.
the class JavaConfigPlaceholderTest method testMultiplePropertySourcesWithSameProperties.
@Test
public void testMultiplePropertySourcesWithSameProperties() throws Exception {
int someTimeout = 1000;
int anotherTimeout = someTimeout + 1;
int someBatch = 2000;
Config application = mock(Config.class);
when(application.getProperty(eq(TIMEOUT_PROPERTY), anyString())).thenReturn(String.valueOf(someTimeout));
when(application.getProperty(eq(BATCH_PROPERTY), anyString())).thenReturn(String.valueOf(someBatch));
mockConfig(ConfigConsts.NAMESPACE_APPLICATION, application);
Config fxApollo = mock(Config.class);
when(fxApollo.getProperty(eq(TIMEOUT_PROPERTY), anyString())).thenReturn(String.valueOf(anotherTimeout));
mockConfig(FX_APOLLO_NAMESPACE, fxApollo);
check(someTimeout, someBatch, AppConfig3.class);
}
use of com.ctrip.framework.apollo.Config in project apollo by ctripcorp.
the class XmlConfigPlaceholderTest method testMultiplePropertySourcesWithSameProperties2.
@Test
public void testMultiplePropertySourcesWithSameProperties2() throws Exception {
int someTimeout = 1000;
int anotherTimeout = someTimeout + 1;
int someBatch = 2000;
Config application = mock(Config.class);
when(application.getProperty(eq(TIMEOUT_PROPERTY), anyString())).thenReturn(String.valueOf(someTimeout));
when(application.getProperty(eq(BATCH_PROPERTY), anyString())).thenReturn(String.valueOf(someBatch));
mockConfig(ConfigConsts.NAMESPACE_APPLICATION, application);
Config fxApollo = mock(Config.class);
when(fxApollo.getProperty(eq(TIMEOUT_PROPERTY), anyString())).thenReturn(String.valueOf(anotherTimeout));
mockConfig(FX_APOLLO_NAMESPACE, fxApollo);
check("spring/XmlConfigPlaceholderTest6.xml", anotherTimeout, someBatch);
}
use of com.ctrip.framework.apollo.Config in project apollo by ctripcorp.
the class ApolloAnnotationProcessor method processField.
@Override
protected void processField(Object bean, String beanName, Field field) {
ApolloConfig annotation = AnnotationUtils.getAnnotation(field, ApolloConfig.class);
if (annotation == null) {
return;
}
Preconditions.checkArgument(Config.class.isAssignableFrom(field.getType()), "Invalid type: %s for field: %s, should be Config", field.getType(), field);
String namespace = annotation.value();
Config config = ConfigService.getConfig(namespace);
ReflectionUtils.makeAccessible(field);
ReflectionUtils.setField(field, bean, config);
}
use of com.ctrip.framework.apollo.Config in project nutzboot by nutzam.
the class ApolloConfigureChangeStarter method start.
public void start() throws Exception {
Config config = ConfigService.getAppConfig();
appContext.getBeans(ConfigChangeListener.class).forEach((listener) -> config.addChangeListener(listener));
}
use of com.ctrip.framework.apollo.Config 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);
}
Aggregations