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

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

Introduction

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

Prototype

public GenericApplicationContext() 

Source Link

Document

Create a new GenericApplicationContext.

Usage

From source file:org.cloudfoundry.identity.uaa.web.ForwardAwareInternalResourceViewResolverTests.java

@Test
public void testResolveForwardWithAccept() throws Exception {
    request.addHeader("Accept", "application/json");
    resolver.setApplicationContext(new GenericApplicationContext());
    View view = resolver.resolveViewName("forward:foo", Locale.US);
    assertNotNull(view);/*from w  ww.j av a2  s  .  c o m*/
}

From source file:net.sourceforge.vulcan.spring.AppCtxTest.java

public void testChildDoesNotReceiveFromParent() throws Exception {
    GenericApplicationContext parent = new GenericApplicationContext();
    parent.refresh();//from   ww w  . ja  v  a  2 s  .  c o  m
    ac.setParent(parent);

    assertNotSame(evt, received);

    parent.publishEvent(evt);

    assertNotSame(evt, received);
}

From source file:com.retroduction.carma.application.CarmaTestExecuter.java

public Summary executeTests() {

    CarmaDriverSetup setup = new CarmaDriverSetup();
    Properties customProps = new Properties();
    try {//w w  w.  j ava 2s. co  m
        customProps.load(new FileInputStream(this.configFile));

    } catch (IOException e) {
        throw new CarmaException("Failed to load configuration", e);
    }

    // merge multiple bean definition sources into application context
    GenericApplicationContext factory = new GenericApplicationContext();

    customProps.setProperty(ICoreConfigConsts.BEAN_REPORTFILE, this.reportFile.getPath());

    // configure maven specific bean references and add beans to parent
    // factory
    // the names in the parent factory should be unique and not overridden
    // by children, otherwise they would have no effect

    customProps.setProperty("project.classesdir.source", BEAN_MAVEN_PROJECT_CLASSES_DIR);
    factory.getBeanFactory().registerSingleton(BEAN_MAVEN_PROJECT_CLASSES_DIR, this.classesDir);

    customProps.setProperty("project.testclassesdir.source", BEAN_MAVEN_PROJECT_TESTCLASSES_DIR);
    factory.getBeanFactory().registerSingleton(BEAN_MAVEN_PROJECT_TESTCLASSES_DIR, this.testClassesDir);

    customProps.setProperty("project.libraries.source", BEAN_MAVEN_PROJECT_LIBRARIES);
    factory.getBeanFactory().registerSingleton(BEAN_MAVEN_PROJECT_LIBRARIES, this.dependencyClassPathUrls);

    setup.setParentContext(factory);
    setup.addCustomConfiguration(customProps);

    // add runtime parameters
    if (this.reportFile.getParentFile() != null) {
        this.reportFile.getParentFile().mkdirs();
    }

    factory.refresh();
    ApplicationContext ctx = setup.getApplicationContext();
    SummaryCreatorEventListener summaryCreator = new SummaryCreatorEventListener();
    ((CompositeEventListener) ctx.getBean("eventListener")).getListeners().add(summaryCreator);

    Core driver = setup.getDriver();
    driver.execute();

    Summary sum = summaryCreator.createSummary();
    return sum;
}

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();/*from  w  w  w  .ja  v  a 2 s. com*/
        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:exercise.cca.data.cli.main.MainCli.java

protected static ConfigurableApplicationContext loadContext(final String contextPath) {
    final GenericApplicationContext ctx = new GenericApplicationContext();
    final XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(ctx);
    xmlReader.loadBeanDefinitions(new ClassPathResource(contextPath));
    final PropertyPlaceholderConfigurer placeholderProcessor = new PropertyPlaceholderConfigurer();
    ctx.addBeanFactoryPostProcessor(placeholderProcessor);
    ctx.refresh();//from  w w w. j  av a  2  s.  c o m
    return ctx;
}

From source file:org.cloudfoundry.identity.uaa.web.ForwardAwareInternalResourceViewResolverTests.java

@Test
public void testResolveForwardWithUnparseableAccept() throws Exception {
    request.addHeader("Accept", "bar");
    resolver.setApplicationContext(new GenericApplicationContext());
    View view = resolver.resolveViewName("forward:foo", Locale.US);
    assertNotNull(view);/*from   www .  jav  a2s.co m*/
}

From source file:org.joinfaces.annotations.JsfCdiToSpringApplicationBeanFactoryPostProcessorIT.java

@Test
public void testSessionScopedClass() {
    GenericApplicationContext acx = new GenericApplicationContext();
    AnnotationConfigUtils.registerAnnotationConfigProcessors(acx);

    acx.registerBeanDefinition("sessionScopedClass",
            new AnnotatedGenericBeanDefinition(new StandardAnnotationMetadata(SessionScopedClass.class)));
    acx.registerBeanDefinition("scopedBeansConfiguration",
            new RootBeanDefinition(ScopedBeansConfiguration.class));
    acx.addBeanFactoryPostProcessor(new JsfCdiToSpringBeanFactoryPostProcessor());
    acx.refresh();//  w  w  w . java2s  .  c o  m

    assertThat(acx.getBeanDefinition("sessionScopedClass").getScope()).isEqualTo(JsfCdiToSpring.SESSION);
    assertThat(acx.getBeanDefinition("sessionScopedBean").getScope()).isEqualTo(JsfCdiToSpring.SESSION);
}

From source file:com.opengamma.engine.calcnode.CalculationNodeProcess.java

private static boolean startContext(final String configuration) {
    try {/*from www.j  a va  2 s  .  com*/
        final GenericApplicationContext context = new GenericApplicationContext();
        final XmlBeanDefinitionReader beanReader = new XmlBeanDefinitionReader(context);
        beanReader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE);
        s_logger.debug("Loading configuration");
        beanReader.loadBeanDefinitions(new InputSource(new StringReader(configuration)));
        s_logger.debug("Instantiating beans");
        context.refresh();
        s_logger.debug("Starting node");
        context.start();
        return true;
    } catch (RuntimeException e) {
        s_logger.warn("Spring initialisation error", e);
        return false;
    }
}

From source file:org.vertx.java.deploy.impl.spring.VertxApplicationContext.java

/**
 * @param loader//from   ww  w.  ja  v  a 2  s. c o m
 * @param vertx
 * @param container 
 */
public VertxApplicationContext(final ClassLoader loader, final Vertx vertx, final Container container) {
    this.vertx = vertx;
    this.container = container;

    this.parent = new GenericApplicationContext();
    parent.setClassLoader(loader);

    ConfigurableListableBeanFactory factory = parent.getBeanFactory();

    factory.registerSingleton(VERTX_BEAN_NAME, this.vertx);
    factory.registerAlias(VERTX_BEAN_NAME, "vertx");

    factory.registerSingleton(EVENTBUS_BEAN_NAME, vertx.eventBus());
    factory.registerAlias(EVENTBUS_BEAN_NAME, "eventBus");

    factory.registerSingleton(VERTICLE_CONTAINER_BEAN_NAME, this.container);
    factory.registerAlias(VERTICLE_CONTAINER_BEAN_NAME, "verticle-container");

    parent.refresh();
    parent.start();
    parent.registerShutdownHook();
}

From source file:net.kamhon.ieagle.application.Application.java

private static void createGenericApplicationContext() {
    if (appContext == null) {
        appContext = new GenericApplicationContext();

        Class<?> clazz = null;
        if (StringUtils.isNotBlank(clazzPath)) {
            try {
                clazz = Class.forName(clazzPath);
            } catch (ClassNotFoundException e) {
                e.printStackTrace();//from   w w  w.j  a  v  a2 s. c om
            }
        }

        ClassPathResource resource = null;
        if (contextPath.startsWith("classpath:")) {
            if (clazz == null) {
                resource = new ClassPathResource(contextPath.substring("classpath:".length()));
            } else {
                resource = new ClassPathResource(contextPath.substring("classpath:".length()), clazz);
            }
        } else {
            if (clazz == null) {
                resource = new ClassPathResource(contextPath);
            } else {
                resource = new ClassPathResource(contextPath, clazz);
            }
        }
        BeanDefinitionReader reader = new XmlBeanDefinitionReader((BeanDefinitionRegistry) appContext);
        reader.loadBeanDefinitions(resource);
        ((GenericApplicationContext) appContext).refresh();
    }
}