Package org.springframework.context.support

Examples of org.springframework.context.support.GenericApplicationContext


        return appContext;
    }

    public static GenericApplicationContext getSpringApplicationContextClassPath(
            ClassLoader classLoader, String relPath) throws AxisFault {
        GenericApplicationContext appContext = new GenericApplicationContext();
        appContext.setClassLoader(classLoader);
        ClassLoader prevCl = Thread.currentThread().getContextClassLoader();
        try {
            Thread.currentThread().setContextClassLoader(classLoader);
            XmlBeanDefinitionReader xbdr = new XmlBeanDefinitionReader(appContext);
            xbdr.setValidating(false);
            InputStream in = classLoader.getResourceAsStream(relPath);
            if (in == null) {
                throw new AxisFault("Spring context cannot be located for AxisService");
            }
            xbdr.loadBeanDefinitions(new InputStreamResource(in));
            appContext.refresh();
        } catch (Exception e) {
            throw AxisFault.makeFault(e);
        } finally {
            // Restore
            Thread.currentThread().setContextClassLoader(prevCl);
View Full Code Here


        return appContext;
    }

    public static GenericApplicationContext getSpringApplicationContext(
            String applicationContxtFilePath, ClassLoader springBeansClassLoader) throws AxisFault {
        GenericApplicationContext appContext = new GenericApplicationContext();

        appContext.setClassLoader(springBeansClassLoader);

        ClassLoader prevCl = Thread.currentThread().getContextClassLoader();

        try {
            // Save the class loader so that you can restore it later
            Thread.currentThread()
                    .setContextClassLoader(
                            new MultiParentClassLoader(new URL[]{}, new ClassLoader[]{
                                    springBeansClassLoader, prevCl}));
            XmlBeanDefinitionReader xbdr = new XmlBeanDefinitionReader(appContext);
            xbdr.setValidating(false);
            xbdr.loadBeanDefinitions(new InputStreamResource(
                    new FileInputStream(new File(applicationContxtFilePath))));
            appContext.refresh();
        } catch (FileNotFoundException e) {
            throw AxisFault.makeFault(e);
        } finally {
            // Restore
            Thread.currentThread().setContextClassLoader(prevCl);
View Full Code Here

        protected ConfigurableApplicationContext createSingleton(Object... args) {
            LOGGER.info("Creating new lazily initialized GenericApplicationContext for the portal");

            final long startTime = System.currentTimeMillis();

            final GenericApplicationContext genericApplicationContext = new GenericApplicationContext();
            final XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(genericApplicationContext);
            reader.setDocumentReaderClass(LazyInitByDefaultBeanDefinitionDocumentReader.class);
            reader.loadBeanDefinitions("/properties/contexts/*.xml");

            genericApplicationContext.refresh();
            genericApplicationContext.registerShutdownHook();

            directCreatorThrowable = new Throwable();
            directCreatorThrowable.fillInStackTrace();
            LOGGER.info("Created new lazily initialized GenericApplicationContext for the portal in " + (System.currentTimeMillis() - startTime) + "ms");

View Full Code Here

            PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer();
            configurer.setSystemPropertiesMode(PropertyPlaceholderConfigurer.SYSTEM_PROPERTIES_MODE_FALLBACK);
            configurer.postProcessBeanFactory(factory);

            context = new GenericApplicationContext(factory);
            context.refresh();

            ServiceContainer container = (ServiceContainer) factory.getBean("container");

            container.start();
View Full Code Here

public class ImportExtensionPointBeanDefinitionReaderTest {

  @Test
  public void testLoadBeanDefinitions() throws Throwable {
    GenericApplicationContext context = new GenericApplicationContext();
    context.setId("testContext");

    ImportExtensionPointBeanDefinitionReader reader = new ImportExtensionPointBeanDefinitionReader(
        context);
    reader.loadBeanDefinitions(context.getId());

    assertNotNull(context.getBean("testBean"));

    assertNotNull(context.getBean("testBean1"));

    assertNotNull(context.getBean("testBean2"));

    assertEquals(context.getBean("testBean1"), ((TestBean) context
        .getBean("testBean2")).getTestBeanProperty());

  }
View Full Code Here

import org.springframework.context.support.GenericApplicationContext;

public class BeansExtensionPointBeanDefinitionReaderTest {
  @Test
  public void testLoadBeanDefinitions() throws Throwable {
    GenericApplicationContext context = new GenericApplicationContext();
    context.setId("testContext");

    BeansExtensionPointBeanDefinitionReader reader = new BeansExtensionPointBeanDefinitionReader(
        context);
    reader.loadBeanDefinitions(context.getId());

    TestBean bean = (TestBean) context.getBean("testBean", TestBean.class);

    assertNotNull(bean);

    assertEquals(context.getBean("testBean2"), bean.getTestBeanProperty());

    assertEquals(-5, bean.getIntProperty());

    assertNotNull(bean.getPropsProperty());

    assertEquals("2", bean.getPropsProperty().getProperty("b"));

    TestBean bean3 = (TestBean) context
        .getBean("testBean3", TestBean.class);

    assertNotNull(bean3);

    assertEquals(58, bean3.getIntProperty());
View Full Code Here

            LOG.debug(String.format("Loading ApplicationContext for merged context configuration [%s].",
                mergedConfig));
        }
       
        try {           
            GenericApplicationContext context = createContext(testClass);
            context.getEnvironment().setActiveProfiles(mergedConfig.getActiveProfiles());
            loadBeanDefinitions(context, mergedConfig);
            return loadContext(context, testClass);
        } finally {
            cleanup(testClass);
        }
View Full Code Here

            LOG.debug("Loading ApplicationContext for locations ["
                    + StringUtils.arrayToCommaDelimitedString(locations) + "].");
        }
       
        try {
            GenericApplicationContext context = createContext(testClass);
            loadBeanDefinitions(context, locations);
            return loadContext(context, testClass);
        } finally {
            cleanup(testClass);
        }
View Full Code Here

     *
     * @return the loaded Spring context
     */
    protected GenericApplicationContext createContext(Class<?> testClass) {

        GenericApplicationContext routeExcludingContext = null;
       
        if (testClass.isAnnotationPresent(ExcludeRoutes.class)) {
            Class<?>[] excludedClasses = testClass.getAnnotation(
                    ExcludeRoutes.class).value();
           
            if (excludedClasses.length > 0) {
               
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Setting up package scanning excluded classes as ExcludeRoutes "
                            + "annotation was found.  Excluding ["
                            + StringUtils.arrayToCommaDelimitedString(excludedClasses) + "].");
                }
               
                routeExcludingContext = new GenericApplicationContext();
                routeExcludingContext.registerBeanDefinition(
                        "excludingResolver", new RootBeanDefinition(
                                ExcludingPackageScanClassResolver.class));
                routeExcludingContext.refresh();
               
                ExcludingPackageScanClassResolver excludingResolver = routeExcludingContext.getBean("excludingResolver", ExcludingPackageScanClassResolver.class);
                List<Class<?>> excluded = CastUtils.cast(Arrays.asList(excludedClasses));
                excludingResolver.setExcludedClasses(new HashSet<Class<?>>(excluded));
            } else {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Not enabling package scanning excluded classes as ExcludeRoutes "
                            + "annotation was found but no classes were excluded.");
                }
            }
        }
       
        GenericApplicationContext context;
       
        if (routeExcludingContext != null) {
            context = new GenericApplicationContext(routeExcludingContext);
        } else {
            context = new GenericApplicationContext();
        }
       
        return context;
    }
View Full Code Here

     *
     * @return ApplicationContext a parent {@link ApplicationContext} configured
     *         to exclude certain classes from package scanning
     */
    protected ApplicationContext getRouteExcludingApplicationContext() {
        GenericApplicationContext routeExcludingContext = new GenericApplicationContext();
        routeExcludingContext.registerBeanDefinition("excludingResolver", new RootBeanDefinition(ExcludingPackageScanClassResolver.class));
        routeExcludingContext.refresh();

        ExcludingPackageScanClassResolver excludingResolver = routeExcludingContext.getBean("excludingResolver", ExcludingPackageScanClassResolver.class);
        List<Class<?>> excluded = CastUtils.cast(Arrays.asList(excludeRoutes()));
        excludingResolver.setExcludedClasses(new HashSet<Class<?>>(excluded));

        return routeExcludingContext;
    }
View Full Code Here

TOP

Related Classes of org.springframework.context.support.GenericApplicationContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.