Example usage for org.springframework.context.support GenericApplicationContext getBeanFactory

List of usage examples for org.springframework.context.support GenericApplicationContext getBeanFactory

Introduction

In this page you can find the example usage for org.springframework.context.support GenericApplicationContext getBeanFactory.

Prototype

@Override
public final ConfigurableListableBeanFactory getBeanFactory() 

Source Link

Document

Return the single internal BeanFactory held by this context (as ConfigurableListableBeanFactory).

Usage

From source file:com.mitre.cockpits.cmscockpit.CmsCockpitConfigurationTest.java

@BeforeClass
public static void testsSetup() {
    Registry.setCurrentTenantByID("junit");
    final GenericApplicationContext context = new GenericApplicationContext();
    context.setResourceLoader(new DefaultResourceLoader(Registry.class.getClassLoader()));
    context.setClassLoader(Registry.class.getClassLoader());
    context.getBeanFactory().setBeanClassLoader(Registry.class.getClassLoader());
    context.setParent(Registry.getGlobalApplicationContext());
    final XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(context);
    xmlReader.setBeanClassLoader(Registry.class.getClassLoader());
    xmlReader.setDocumentReaderClass(ScopeTenantIgnoreDocReader.class);
    xmlReader.loadBeanDefinitions(getSpringConfigurationLocations());
    context.refresh();//  w ww  . j av  a  2s .co  m
    applicationContext = context;
}

From source file:com.brienwheeler.lib.spring.beans.PropertyPlaceholderConfigurer.java

/**
 * Programatically process a single property file location, using System
 * properties in preference to included definitions for placeholder
 * resolution, and setting any resolved properties as System properties, if
 * no property by that name already exists.
 * //  w ww.ja  va  2 s .com
 * @param locationName String-encoded resource location for the properties file to process
 * @param placeholderPrefix the placeholder prefix String
 * @param placeholderSuffix the placeholder suffix String
 */
public static void processLocation(String locationName, String placeholderPrefix, String placeholderSuffix) {
    ResourceEditor resourceEditor = new ResourceEditor();
    resourceEditor.setAsText(locationName);

    PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer();
    configurer.setLocation((Resource) resourceEditor.getValue());
    if (placeholderPrefix != null)
        configurer.setPlaceholderPrefix(placeholderPrefix);
    if (placeholderSuffix != null)
        configurer.setPlaceholderSuffix(placeholderSuffix);
    configurer.quiet = true;

    GenericApplicationContext context = new GenericApplicationContext();
    context.getBeanFactory().registerSingleton("propertyPlaceholderConfigurer", configurer);
    context.refresh();
    context.close();
}

From source file:com.himanshu.spring.context.loader.diffconfigpercontext.ServiceFactoryDiffConfigPerContext.java

private ApplicationContext getParentContext() {
    GenericApplicationContext parentContext = new GenericApplicationContext();
    parentContext.getBeanFactory().registerSingleton("dummyBean", this);
    parentContext.getBeanFactory().registerSingleton("mainContext", context);
    parentContext.refresh();// w w w  . j a v a2s  .c  o  m
    return parentContext;
}

From source file:com.graphaware.server.web.WebAppInitializer.java

@Override
protected WebApplicationContext createServletApplicationContext() {
    GenericApplicationContext parent = new GenericApplicationContext();
    parent.getBeanFactory().registerSingleton("database", database.getGraph());

    GraphAwareRuntime runtime = RuntimeRegistry.getRuntime(database.getGraph());
    if (runtime != null) {
        runtime.waitUntilStarted();/*from  w w w.jav  a2s.  co m*/
        parent.getBeanFactory().registerSingleton("databaseWriter", runtime.getDatabaseWriter());
    }

    parent.refresh();

    AnnotationConfigWebApplicationContext appContext = new AnnotationConfigWebApplicationContext();
    appContext.setParent(parent);
    appContext.scan("com.**.graphaware.**", "org.**.graphaware.**", "net.**.graphaware.**");

    return appContext;
}

From source file:com.graphaware.server.foundation.context.FoundationRootContextCreator.java

@Override
public AbstractApplicationContext createContext(NeoServer neoServer, StatsCollector statsCollector) {
    GenericApplicationContext parent = new GenericApplicationContext();
    parent.registerShutdownHook();//from   w  w  w  .  j  ava  2  s  . c  om
    parent.getBeanFactory().registerSingleton("database", neoServer.getDatabase().getGraph());
    parent.getBeanFactory().registerSingleton("procedures",
            neoServer.getDatabase().getGraph().getDependencyResolver().resolveDependency(Procedures.class));

    parent.getBeanFactory().registerSingleton("getStatsCollector", statsCollector);

    GraphAwareRuntime runtime = RuntimeRegistry.getRuntime(neoServer.getDatabase().getGraph());
    if (runtime != null) {
        runtime.waitUntilStarted();
        parent.getBeanFactory().registerSingleton("databaseWriter", runtime.getDatabaseWriter());
    }

    parent.refresh();

    return parent;
}

From source file:org.wte4j.examples.showcase.server.config.WebContextTestExecutionListener.java

@Override
public void prepareTestInstance(TestContext testContext) {
    if (testContext.getApplicationContext() instanceof GenericApplicationContext) {
        GenericApplicationContext context = (GenericApplicationContext) testContext.getApplicationContext();
        ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
        beanFactory.registerScope(WebApplicationContext.SCOPE_REQUEST, new SimpleThreadScope());
        beanFactory.registerScope(WebApplicationContext.SCOPE_SESSION, new SimpleThreadScope());
    }/*from  w ww.ja v  a  2  s .  c  om*/
}

From source file:dhbw.ka.mwi.businesshorizon2.tests.ui.assets.TestExecutionListener.java

@Override
public void prepareTestInstance(TestContext testContext) throws Exception {

    if (testContext.getApplicationContext() instanceof GenericApplicationContext) {
        GenericApplicationContext context = (GenericApplicationContext) testContext.getApplicationContext();
        ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
        Scope requestScope = new SimpleThreadScope();
        beanFactory.registerScope("request", requestScope);
        Scope sessionScope = new SimpleThreadScope();
        beanFactory.registerScope("session", sessionScope);
    }/*from   ww  w . ja  va 2 s. c om*/
}

From source file:org.alfresco.cacheserver.dropwizard.Application.java

public void start() {
    if (springContextFileLocation != null) {
        // parent spring context with the normal DropWizard configuration defined
        GenericApplicationContext parent = new GenericApplicationContext();
        parent.refresh();//ww  w  . j av  a 2s .c  o  m
        parent.getBeanFactory().registerSingleton("configuration", this);
        parent.registerShutdownHook();
        parent.start();

        try {
            PropertyPlaceholderConfigurer configurer = loadSpringConfigurer(yamlConfigFileLocation);

            // child spring context from xml
            context = new ClassPathXmlApplicationContext(parent);
            if (configurer != null) {
                context.addBeanFactoryPostProcessor(configurer);
            }
            context.setConfigLocations(new String[] { springContextFileLocation });
            context.registerShutdownHook();
            context.refresh();
        } catch (IOException e) {
            throw new IllegalStateException("Could not create Spring context", e);
        }
    } else {
        throw new IllegalArgumentException("Spring context file location not set");
    }
}

From source file:fi.okm.mpass.shibboleth.profile.metadata.DataSourceMetadataResolverTest.java

public DataSourceMetadataResolver getResolver() throws Exception {
    GenericApplicationContext context = new GenericApplicationContext();
    context.getBeanFactory().addBeanPostProcessor(new IdentifiableBeanPostProcessor());
    return getBean(BASE_PATH_BEANS + "/dataSourceEntity.xml", DataSourceMetadataResolver.class, context, false);
}

From source file:org.apache.zeppelin.lens.LensBootstrap.java

public LensJLineShellComponent getLensJLineShellComponent() {
    GenericApplicationContext ctx = (GenericApplicationContext) getApplicationContext();
    RootBeanDefinition rbd = new RootBeanDefinition();
    rbd.setBeanClass(LensJLineShellComponent.class);
    DefaultListableBeanFactory bf = (DefaultListableBeanFactory) ctx.getBeanFactory();
    bf.registerBeanDefinition(LensJLineShellComponent.class.getSimpleName(), rbd);
    return ctx.getBean(LensJLineShellComponent.class);
}