Package org.springframework.context.support

Examples of org.springframework.context.support.GenericApplicationContext


     *
     * @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 = (ExcludingPackageScanClassResolver)routeExcludingContext.getBean("excludingResolver");
        List<Class<?>> excluded = CastUtils.cast(Arrays.asList(excludeRoutes()));
        excludingResolver.setExcludedClasses(new HashSet<Class<?>>(excluded));

        return routeExcludingContext;
    }
View Full Code Here


        context.refresh();

        // Have to create a child context that implements BeanDefinitionRegistry
        // to pass to registerAnnotationConfigProcessors, since
        // JavaConfigApplicationContext does not
        final GenericApplicationContext gac = new GenericApplicationContext(context);
        AnnotationConfigUtils.registerAnnotationConfigProcessors(gac);
        // copy BeanPostProcessors to the child context
        for (String bppName : context.getBeanFactory().getBeanNamesForType(BeanPostProcessor.class)) {
            gac.registerBeanDefinition(bppName, context.getBeanFactory().getBeanDefinition(bppName));
        }
        gac.refresh();
        gac.registerShutdownHook();

        return gac;
    }
View Full Code Here

  public void test() throws Exception {

    Properties properties = new Properties();
    properties.load(this.getClass().getClassLoader().getResourceAsStream("beanset/beanset.properties"));

    GenericApplicationContext context = createContext(properties, "imported-context.xml");

    assertTrue(context.getBean("bean1") instanceof Bean1);
    assertTrue(context.getBean("bean2") instanceof Bean2);
    assertTrue(context.getBean("bean3") instanceof Bean3);

    properties.setProperty("bean2and3", "alternative-context.xml");
    context = createContext(properties, "alternative-context.xml");

    assertTrue(context.getBean("bean1") instanceof Bean1);
    assertTrue(context.getBean("bean2") instanceof Bean4);

    try {
      context.getBean("bean3");
      fail();
    }
    catch (NoSuchBeanDefinitionException e) {
    }
View Full Code Here

    }

  }

  protected GenericApplicationContext createContext(final Properties properties, String expectedResource) {
    GenericApplicationContext context = new GenericApplicationContext();
   
    final RecordingImportingBeanDefinitionDocumentReader documentReader = new RecordingImportingBeanDefinitionDocumentReader(properties);

    XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(context){
      @Override
View Full Code Here

 
  public final void testNewBeanDefinitionReader() {
    BeansetModuleDefinition definition = new SimpleBeansetModuleDefinition(plugin4);
    BeansetApplicationModuleLoader loader = new BeansetApplicationModuleLoader();
 
    XmlBeanDefinitionReader reader = loader.newBeanDefinitionReader("id", new GenericApplicationContext(), definition);
    int definitions = reader.loadBeanDefinitions(new ClassPathResource("parentTestContext.xml"));
    assertTrue(definitions > 0);
  }
View Full Code Here

    DynamicScope dynamicScope = new DynamicScope();
    dynamicScope.setClassLoader(classLoader);
    beanFactory.registerScope("dynamic", dynamicScope);

    // create the application context, and set the class loader
    GenericApplicationContext context = new GenericApplicationContext(beanFactory);
    context.setClassLoader(classLoader);

    // create the bean definition reader
    XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(context);
    xmlReader.loadBeanDefinitions(new ClassPathResource("dynamic/dynamic-context.xml", classLoader));

    // refresh the application context - now we're ready to go
    context.refresh();

    assertNotNull(context.getBean("communicationMethod"));
    assertNotNull(context.getBean("communicationMethodImpl"));

    Person ti = (Person) context.getBean("person");

    while (true) {
      ti.act();
      Thread.sleep(500);
    }
View Full Code Here

       
        DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
        beanFactory.setBeanClassLoader(classLoader);

        // create the application context, and set the class loader
        GenericApplicationContext context = new GenericApplicationContext(beanFactory, parent);
        context.setClassLoader(classLoader);
        context.setDisplayName(ModuleLoaderUtils.getDisplayName(definition, context));
        return context;
    }
View Full Code Here

   
    DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
    beanFactory.setBeanClassLoader(classLoader);

    // create the application context, and set the class loader
    GenericApplicationContext context = new GenericApplicationContext(beanFactory, parent);
    context.setClassLoader(classLoader);
    return context;
  }
View Full Code Here

        loader.setServletContext(servletContext);
    }
   
    public final void testNewApplicationContext() {
        final ClassLoader classLoader = ClassUtils.getDefaultClassLoader();
        final GenericApplicationContext parent = new GenericApplicationContext();
        final GenericWebApplicationContext applicationContext = loader.newApplicationContext(null, parent, new SimpleRootModuleDefinition(projectNames, new String[]{"loc"}), classLoader);

        assertNotNull(applicationContext);
        assertNotNull(applicationContext.getBeanFactory());
        assertSame(classLoader, applicationContext.getClassLoader());
View Full Code Here

* @author Phil Zoio
*/
public class ExpandableTest extends TestCase {

  public void test() throws InterruptedException {
    GenericApplicationContext context = new GenericApplicationContext();

    XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(context);
    xmlReader.loadBeanDefinitions(new ClassPathResource("expandable/core-context.xml"));

    context.refresh();

    RootModuleContextMonitor monitor = new RootModuleContextMonitor(xmlReader, new ClassPathResource(
        "expandable/spring-locations.txt"), new ScheduledThreadPoolExecutor(1));
    monitor.setupMonitor();

    context.getBean("coreBean");

    while (true) {
      try {
        Thread.sleep(1000);
        Object bean = context.getBean("extraBean");
        System.out.println("Found bean named 'extraBean' in context: " + bean.getClass().getName());
      }
      catch (NoSuchBeanDefinitionException e) {
        System.out.println("No bean named 'extraBean' found in context");
      }
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.