use of org.craftercms.commons.spring.ApacheCommonsConfiguration2PropertySource in project engine by craftercms.
the class SiteContextFactory method getApplicationContext.
protected ConfigurableApplicationContext getApplicationContext(SiteContext siteContext, URLClassLoader classLoader, HierarchicalConfiguration config, String[] applicationContextPaths, ResourceLoader resourceLoader) {
try {
List<Resource> resources = new ArrayList<>();
for (String path : applicationContextPaths) {
Resource resource = resourceLoader.getResource(path);
if (resource.exists()) {
resources.add(resource);
}
}
if (CollectionUtils.isNotEmpty(resources)) {
String siteName = siteContext.getSiteName();
logger.info("--------------------------------------------------");
logger.info("<Loading application context for site: " + siteName + ">");
logger.info("--------------------------------------------------");
GenericApplicationContext appContext = new GenericApplicationContext(globalApplicationContext);
appContext.setClassLoader(classLoader);
if (config != null) {
MutablePropertySources propertySources = appContext.getEnvironment().getPropertySources();
propertySources.addFirst(new ApacheCommonsConfiguration2PropertySource("siteConfig", config));
}
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(appContext);
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD);
for (Resource resource : resources) {
reader.loadBeanDefinitions(resource);
}
appContext.refresh();
logger.info("--------------------------------------------------");
logger.info("</Loading application context for site: " + siteName + ">");
logger.info("--------------------------------------------------");
return appContext;
} else {
return null;
}
} catch (Exception e) {
throw new SiteContextCreationException("Unable to load application context for site '" + siteContext.getSiteName() + "'", e);
}
}
Aggregations