use of com.ctrip.framework.apollo.Config in project apollo by ctripcorp.
the class ApolloAnnotationProcessor method processMethod.
@Override
protected void processMethod(final Object bean, String beanName, final Method method) {
ApolloConfigChangeListener annotation = AnnotationUtils.findAnnotation(method, ApolloConfigChangeListener.class);
if (annotation == null) {
return;
}
Class<?>[] parameterTypes = method.getParameterTypes();
Preconditions.checkArgument(parameterTypes.length == 1, "Invalid number of parameters: %s for method: %s, should be 1", parameterTypes.length, method);
Preconditions.checkArgument(ConfigChangeEvent.class.isAssignableFrom(parameterTypes[0]), "Invalid parameter type: %s for method: %s, should be ConfigChangeEvent", parameterTypes[0], method);
ReflectionUtils.makeAccessible(method);
String[] namespaces = annotation.value();
ConfigChangeListener configChangeListener = new ConfigChangeListener() {
@Override
public void onChange(ConfigChangeEvent changeEvent) {
ReflectionUtils.invokeMethod(method, bean, changeEvent);
}
};
for (String namespace : namespaces) {
Config config = ConfigService.getConfig(namespace);
config.addChangeListener(configChangeListener);
}
}
use of com.ctrip.framework.apollo.Config in project duangframework by tcrct.
the class SimpleApolloConfig method getConfig.
/**
* 根据关键字取配置信息值
* 先取私有空间的,再取公有或关联的,取公有或关联里第一个匹配的信息返回并退出
* @param key 关键字
* @return
*/
public String getConfig(String key) {
String result = appConfig.getProperty(key, DEFAULT_VALUE);
if (DEFAULT_VALUE.equals(result)) {
for (String nameSpace : configMaps.keySet()) {
Config config = configMaps.get(nameSpace);
if (null != config) {
result = config.getProperty(key, DEFAULT_VALUE);
if (!DEFAULT_VALUE.equals(result)) {
break;
}
}
}
}
logger.warn(String.format("Loading key : %s with value: %s", key, result));
return DEFAULT_VALUE.equals(result) ? "" : result;
}
use of com.ctrip.framework.apollo.Config in project nutzboot by nutzam.
the class ApolloConfigureLoader method init.
public void init() throws Exception {
Config config = ConfigService.getAppConfig();
conf = new PropertiesProxy();
config.getPropertyNames().forEach((key) -> conf.put(key, config.getProperty(key, null)));
}
use of com.ctrip.framework.apollo.Config in project SpringCloudDemo by RickJou.
the class ApolloJavaClientDemo method privateConfig.
public static void privateConfig() {
// 私有配置
String privateNamespace = "application";
Config privateConfig = ConfigService.getConfig(privateNamespace);
String someKey = "private-key1";
String someDefaultValue = "defaultValue";
String value = privateConfig.getProperty(someKey, someDefaultValue);
log.info("私有配置" + someKey + ":" + value);
// 私有配置基础了公有配置,所以可以获取共有配置
String somePublicNamespace = "org1.public-namespace";
// config instance is singleton for each namespace and is never null
Config config = ConfigService.getConfig(somePublicNamespace);
someKey = "common.setting.value";
someDefaultValue = "someDefaultValueForTheKey";
value = config.getProperty(someKey, someDefaultValue);
log.info("公共配置" + someKey + ":" + value);
}
use of com.ctrip.framework.apollo.Config in project apollo by ctripcorp.
the class DefaultConfigManager method getConfig.
@Override
public Config getConfig(String namespace) {
Config config = m_configs.get(namespace);
if (config == null) {
synchronized (this) {
config = m_configs.get(namespace);
if (config == null) {
ConfigFactory factory = m_factoryManager.getFactory(namespace);
config = factory.create(namespace);
m_configs.put(namespace, config);
}
}
}
return config;
}
Aggregations