Search in sources :

Example 1 with ResourceApplicationContext

use of com.cloud.spring.module.context.ResourceApplicationContext in project cosmic by MissionCriticalCloud.

the class DefaultModuleDefinitionSet method getDefaultsContext.

protected ApplicationContext getDefaultsContext() {
    final URL config = DefaultModuleDefinitionSet.class.getResource(DEFAULT_CONFIG_XML);
    final ResourceApplicationContext context = new ResourceApplicationContext(new UrlResource(config));
    context.setApplicationName("/defaults");
    context.refresh();
    final List<Resource> resources = (List<Resource>) context.getBean(DEFAULT_CONFIG_RESOURCES);
    withModule((def, parents) -> {
        for (final Resource defaults : def.getConfigLocations()) {
            resources.add(defaults);
        }
    });
    configProperties = (Properties) context.getBean(DEFAULT_CONFIG_PROPERTIES);
    for (final Resource resource : resources) {
        load(resource, configProperties);
    }
    for (final Resource resource : (Resource[]) context.getBean(MODULE_PROPERITES)) {
        load(resource, configProperties);
    }
    parseExcludes();
    return context;
}
Also used : UrlResource(org.springframework.core.io.UrlResource) UrlResource(org.springframework.core.io.UrlResource) Resource(org.springframework.core.io.Resource) ResourceApplicationContext(com.cloud.spring.module.context.ResourceApplicationContext) ArrayList(java.util.ArrayList) List(java.util.List) URL(java.net.URL)

Example 2 with ResourceApplicationContext

use of com.cloud.spring.module.context.ResourceApplicationContext in project cosmic by MissionCriticalCloud.

the class DefaultModuleDefinitionSet method loadContext.

protected ApplicationContext loadContext(final ModuleDefinition def, final ApplicationContext parent) {
    final ResourceApplicationContext context = new ResourceApplicationContext();
    context.setApplicationName("/" + def.getName());
    final Resource[] resources = getConfigResources(def.getName());
    context.setConfigResources(resources);
    context.setParent(parent);
    context.setClassLoader(def.getClassLoader());
    final long start = System.currentTimeMillis();
    if (log.isInfoEnabled()) {
        for (final Resource resource : resources) {
            log.info("Loading module context [{}] from {}", def.getName(), resource);
        }
    }
    context.refresh();
    log.info("Loaded module context [{}] in {} ms", def.getName(), (System.currentTimeMillis() - start));
    contexts.put(def.getName(), context);
    return context;
}
Also used : UrlResource(org.springframework.core.io.UrlResource) Resource(org.springframework.core.io.Resource) ResourceApplicationContext(com.cloud.spring.module.context.ResourceApplicationContext)

Aggregations

ResourceApplicationContext (com.cloud.spring.module.context.ResourceApplicationContext)2 Resource (org.springframework.core.io.Resource)2 UrlResource (org.springframework.core.io.UrlResource)2 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1