use of org.apache.servicecomb.config.archaius.sources.MicroserviceConfigLoader in project incubator-servicecomb-java-chassis by apache.
the class TestConfigurationSpringInitializer method testAll.
@Test
public void testAll() {
ConfigurationSpringInitializer configurationSpringInitializer = new ConfigurationSpringInitializer();
Assert.assertEquals(Ordered.LOWEST_PRECEDENCE / 2, configurationSpringInitializer.getOrder());
Assert.assertEquals(true, Deencapsulation.getField(configurationSpringInitializer, "ignoreUnresolvablePlaceholders"));
Object o = ConfigUtil.getProperty("zq");
@SuppressWarnings("unchecked") List<Map<String, Object>> listO = (List<Map<String, Object>>) o;
Assert.assertEquals(3, listO.size());
Assert.assertEquals(null, ConfigUtil.getProperty("notExist"));
MicroserviceConfigLoader loader = ConfigUtil.getMicroserviceConfigLoader();
Assert.assertNotNull(loader);
Configuration instance = ConfigurationManager.getConfigInstance();
ConfigUtil.installDynamicConfig();
// must not reinstall
Assert.assertEquals(instance, ConfigurationManager.getConfigInstance());
}
use of org.apache.servicecomb.config.archaius.sources.MicroserviceConfigLoader in project incubator-servicecomb-java-chassis by apache.
the class ConfigUtil method createLocalConfig.
public static ConcurrentCompositeConfiguration createLocalConfig() {
MicroserviceConfigLoader loader = new MicroserviceConfigLoader();
loader.loadAndSort();
LOGGER.info("create local config:");
for (ConfigModel configModel : loader.getConfigModels()) {
LOGGER.info(" {}.", configModel.getUrl());
}
ConcurrentCompositeConfiguration config = ConfigUtil.createLocalConfig(loader.getConfigModels());
ConfigUtil.setMicroserviceConfigLoader(config, loader);
return config;
}
use of org.apache.servicecomb.config.archaius.sources.MicroserviceConfigLoader in project java-chassis by ServiceComb.
the class ConfigurationSpringInitializer method addMicroserviceYAMLToSpring.
/**
* make springboot have a change to add microservice.yaml source earlier<br>
* to affect {@link Conditional}
* @param environment environment
*/
private static void addMicroserviceYAMLToSpring(Environment environment) {
if (!(environment instanceof ConfigurableEnvironment)) {
return;
}
MutablePropertySources propertySources = ((ConfigurableEnvironment) environment).getPropertySources();
if (propertySources.contains(MICROSERVICE_PROPERTY_SOURCE_NAME)) {
return;
}
propertySources.addLast(new EnumerablePropertySource<MicroserviceConfigLoader>(MICROSERVICE_PROPERTY_SOURCE_NAME) {
private final Map<String, Object> values = new HashMap<>();
private final String[] propertyNames;
{
MicroserviceConfigLoader loader = new MicroserviceConfigLoader();
loader.loadAndSort();
loader.getConfigModels().forEach(configModel -> values.putAll(YAMLUtil.retrieveItems("", configModel.getConfig())));
propertyNames = values.keySet().toArray(new String[values.size()]);
}
@Override
public String[] getPropertyNames() {
return propertyNames;
}
@SuppressWarnings("unchecked")
@Override
public Object getProperty(String name) {
Object value = this.values.get(name);
// spring will not resolve nested placeholder of list, so try to fix the problem
if (value instanceof List) {
value = ((List<Object>) value).stream().filter(item -> item instanceof String).map(item -> environment.resolvePlaceholders((String) item)).collect(Collectors.toList());
}
return value;
}
});
}
Aggregations