public static ApplicationContext newApplicationContext(ManagementContext mgmt, ResourceLoader resourceLoader) throws Exception {
log.info("Loading Alien4Cloud platform...");
// TODO if ES cannot find a config file, it will hang waiting for peers; should warn if does not complete in 1m
try {
Stopwatch s = Stopwatch.createStarted();
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
if (null != resourceLoader) {
ctx.setResourceLoader(resourceLoader);
}
// messy, but seems we must manually load the properties before loading the beans; otherwise we get e.g.
// Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'directories.alien' in string value "${directories.alien}/plugins"
final YamlPropertiesFactoryBean yamlPropertiesFactoryBean = AlienBrooklynYamlPropertiesFactoryBeanFactory.get(mgmt, ctx);
if (yamlPropertiesFactoryBean == null) {
throw new IllegalStateException("Could not load configuration for A4C. Expected either a value for ConfigKey " +
AlienBrooklynYamlPropertiesFactoryBeanFactory.ALIEN_CONFIG_FILE.getName() + " or for a resource named " +
AlienYamlPropertiesFactoryBeanFactory.ALIEN_CONFIGURATION_YAML + " to be available.");
}
ctx.getEnvironment().getPropertySources().addFirst(new PropertiesPropertySource("user",
yamlPropertiesFactoryBean.getObject()));
ctx.getBeanFactory().registerSingleton("brooklynManagementContext", mgmt);
ctx.register(Alien4CloudSpringContext.class, Alien4CloudSpringConfig.class);
ctx.refresh();
ctx.registerShutdownHook();
log.info("Finished loading Alien4Cloud platform (" + Duration.of(s) + ")");
return ctx;
} catch (Throwable t) {
log.warn("Errors loading Alien4Cloud platform (rethrowing): " + t, t);
throw Exceptions.propagate(t);
}
}
Alien4CloudSpringContext.java 文件源码
java
阅读 33
收藏 0
点赞 0
评论 0
项目:brooklyn-tosca
作者:
评论列表
文章目录