Example usage for org.springframework.web.context.support GenericWebApplicationContext getBean

List of usage examples for org.springframework.web.context.support GenericWebApplicationContext getBean

Introduction

In this page you can find the example usage for org.springframework.web.context.support GenericWebApplicationContext getBean.

Prototype

@Override
    public Object getBean(String name) throws BeansException 

Source Link

Usage

From source file:org.impalaframework.web.spring.loader.BaseImpalaContextLoader.java

/**
 * Instantiates Impala in the form of a <code>ModuleManagementFacade</code> instance.
 *//*from   ww w .  j a v  a2s  .  com*/
protected ModuleManagementFacade createModuleManagementFacade(ServletContext servletContext,
        WebApplicationContext parent) {

    String[] locations = getBootstrapContextLocations(servletContext);
    logger.info("Loading bootstrap context from locations " + Arrays.toString(locations));

    final DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
    final GenericWebApplicationContext applicationContext = new GenericWebApplicationContext(beanFactory);
    applicationContext.setServletContext(servletContext);
    applicationContext.setParent(parent);

    XmlBeanDefinitionReader definitionReader = new XmlBeanDefinitionReader(beanFactory);
    for (int i = 0; i < locations.length; i++) {
        definitionReader.loadBeanDefinitions(new ClassPathResource(locations[i]));
    }
    applicationContext.refresh();

    return ObjectUtils.cast(applicationContext.getBean("moduleManagementFacade"), ModuleManagementFacade.class);
}

From source file:ubic.gemma.util.SpringContextUtil.java

/**
 * Adds the resource to the application context and sets the parentContext as the parent of the resource
 * //w w w  .  java2  s .co m
 * @param parentContext
 * @param resource
 * @return {@link ApplicationContext}
 */
public static ApplicationContext addResourceToContext(ApplicationContext parentContext,
        ClassPathResource resource) {
    GenericWebApplicationContext spacesBeans = new GenericWebApplicationContext();
    XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(spacesBeans);
    xmlReader.loadBeanDefinitions(resource);

    spacesBeans.setParent(parentContext);

    CommonsConfigurationPropertyPlaceholderConfigurer configurationPropertyConfigurer = (CommonsConfigurationPropertyPlaceholderConfigurer) spacesBeans
            .getBean("configurationPropertyConfigurer");
    configurationPropertyConfigurer.postProcessBeanFactory(spacesBeans.getBeanFactory());

    spacesBeans.refresh();

    return spacesBeans;
}