/** * Create a new GenericApplicationContext with the given DefaultListableBeanFactory. * @param beanFactory the DefaultListableBeanFactory instance to use for this context * @param parent the parent application context * @see #registerBeanDefinition * @see #refresh */ public GenericApplicationContext(DefaultListableBeanFactory beanFactory, ApplicationContext parent) { this(beanFactory); setParent(parent); }
/** * Create a new GenericApplicationContext with the given DefaultListableBeanFactory. * @param beanFactory the DefaultListableBeanFactory instance to use for this context * @param parent the parent application context * @see #registerBeanDefinition * @see #refresh */ public GenericApplicationContext(DefaultListableBeanFactory beanFactory, ApplicationContext parent) { this(beanFactory); setParent(parent); }
/** * Create a new GenericApplicationContext with the given parent. * @param parent the parent application context * @see #registerBeanDefinition * @see #refresh */ public GenericApplicationContext(@Nullable ApplicationContext parent) { this(); setParent(parent); }
/** * Create a new GenericApplicationContext with the given parent. * @param parent the parent application context * @see #registerBeanDefinition * @see #refresh */ public GenericApplicationContext(@Nullable ApplicationContext parent) { this(); setParent(parent); }
public ApplicationContextHelper(ConfigurableApplicationContext parent, GenericApplicationContext context, Object... config) { this.parent = parent; if (parent != null) { Assert.isTrue(parent.getBeanFactory() instanceof DefaultListableBeanFactory, "The parent application context must have a bean factory of type DefaultListableBeanFactory"); parentBeanFactory = (DefaultListableBeanFactory) parent.getBeanFactory(); } else { parentBeanFactory = null; } context.setParent(parent); context.setId(generateId(config)); loadConfiguration(config); prepareContext(parent, context); }
context.setParent(parent);
@Test public void testDefaultApplicationContextMessageSourceWithParent() { GenericApplicationContext ac = new GenericApplicationContext(); GenericApplicationContext parent = new GenericApplicationContext(); parent.refresh(); ac.setParent(parent); ac.refresh(); assertEquals("default", ac.getMessage("code1", null, "default", Locale.ENGLISH)); assertEquals("default value", ac.getMessage("code1", new Object[] {"value"}, "default {0}", Locale.ENGLISH)); }
@Override protected void customizeContext(GenericApplicationContext context) { GenericXmlApplicationContext parent = new GenericXmlApplicationContext(); parent.setEnvironment(TestProfileEnvironment.getEnvironment()); parent.load(parentLocation); parent.refresh(); super.customizeContext(context); context.setParent(parent); } }
@Test public void verifySinglePostProcessor() { ClassPathXmlApplicationContext parent = new ClassPathXmlApplicationContext( "hierarchyTests-parent.xml", this.getClass()); parent.refresh(); GenericApplicationContext child = new GenericApplicationContext(); child.setParent(parent); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(child); reader.loadBeanDefinitions(new ClassPathResource("hierarchyTests-child.xml", this.getClass())); child.refresh(); assertSame(parent.getBean(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME), child.getBean(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME)); assertSame(parent.getBean(IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME), child.getBean(IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME)); assertSame(parent.getBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME), child.getBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME)); }
/** * Create a new GenericApplicationContext with the given DefaultListableBeanFactory. * @param beanFactory the DefaultListableBeanFactory instance to use for this context * @param parent the parent application context * @see #registerBeanDefinition * @see #refresh */ public GenericApplicationContext(DefaultListableBeanFactory beanFactory, ApplicationContext parent) { this(beanFactory); setParent(parent); }
@Override public void setParentContext(ApplicationContext parentContext) { this.context.setParent(parentContext); }
/** * Create a new GenericApplicationContext with the given parent. * @param parent the parent application context * @see #registerBeanDefinition * @see #refresh */ public GenericApplicationContext(@Nullable ApplicationContext parent) { this(); setParent(parent); }
@Override public void setParent(ApplicationContext parent) { parentProxy=new ApplicationContextProxy(parent,this); super.setParent(parentProxy); }
@Test public void testParentConversionServiceAvailability() { ClassPathXmlApplicationContext parentContext = new ClassPathXmlApplicationContext( "ConverterParserWithExistingConversionServiceTests-parent.xml", ConverterParserWithExistingConversionServiceTests.class); GenericApplicationContext childContext = new GenericApplicationContext(); childContext.setParent(parentContext); childContext.refresh(); GenericConversionService conversionServiceParent = parentContext.getBean(IntegrationUtils.INTEGRATION_CONVERSION_SERVICE_BEAN_NAME, GenericConversionService.class); GenericConversionService conversionServiceChild = childContext.getBean(IntegrationUtils.INTEGRATION_CONVERSION_SERVICE_BEAN_NAME, GenericConversionService.class); assertTrue(conversionServiceParent == conversionServiceChild); // validating that they are pointing to the same object conversionServiceChild.addConverter(new TestConverter()); conversionServiceChild.addConverter(new TestConverter3()); assertTrue(conversionServiceChild.canConvert(TestBean1.class, TestBean2.class)); assertTrue(conversionServiceChild.canConvert(TestBean1.class, TestBean3.class)); childContext.close(); parentContext.close(); }
GenericApplicationContext context = new GenericApplicationContext(); context.setParent(parentContext); parentContext.refresh();
GenericApplicationContext context = new GenericApplicationContext(); context.setParent(applicationContext); context.registerBeanDefinition("beandefName", beanDefinitionObject);
public ApplicationContextHelper(ConfigurableApplicationContext parent, GenericApplicationContext context, Object... config) { this.parent = parent; if (parent != null) { Assert.isTrue(parent.getBeanFactory() instanceof DefaultListableBeanFactory, "The parent application context must have a bean factory of type DefaultListableBeanFactory"); parentBeanFactory = (DefaultListableBeanFactory) parent.getBeanFactory(); } else { parentBeanFactory = null; } context.setParent(parent); context.setId(generateId(config)); loadConfiguration(config); prepareContext(parent, context); }
public ApplicationContextHelper(ConfigurableApplicationContext parent, GenericApplicationContext context, Object... config) { this.parent = parent; if (parent != null) { Assert.isTrue(parent.getBeanFactory() instanceof DefaultListableBeanFactory, "The parent application context must have a bean factory of type DefaultListableBeanFactory"); parentBeanFactory = (DefaultListableBeanFactory) parent.getBeanFactory(); } else { parentBeanFactory = null; } context.setParent(parent); context.setId(generateId(config)); loadConfiguration(config); prepareContext(parent, context); }
public ApplicationContextHelper(ConfigurableApplicationContext parent, GenericApplicationContext context, Object... config) { this.parent = parent; if (parent != null) { Assert.isTrue(parent.getBeanFactory() instanceof DefaultListableBeanFactory, "The parent application context must have a bean factory of type DefaultListableBeanFactory"); parentBeanFactory = (DefaultListableBeanFactory) parent.getBeanFactory(); } else { parentBeanFactory = null; } context.setParent(parent); context.setId(generateId(config)); loadConfiguration(config); prepareContext(parent, context); }
private GenericApplicationContext createFlowApplicationContext(Resource[] resources) { ApplicationContext parent = getContext().getApplicationContext(); GenericApplicationContext flowContext; if (parent instanceof WebApplicationContext) { GenericWebApplicationContext webContext = new GenericWebApplicationContext(); webContext.setServletContext(((WebApplicationContext) parent).getServletContext()); flowContext = webContext; } else { flowContext = new GenericApplicationContext(); } flowContext.setDisplayName("Flow ApplicationContext [" + getContext().getFlowId() + "]"); flowContext.setParent(parent); flowContext.getBeanFactory().registerScope("request", new RequestScope()); flowContext.getBeanFactory().registerScope("flash", new FlashScope()); flowContext.getBeanFactory().registerScope("view", new ViewScope()); flowContext.getBeanFactory().registerScope("flow", new FlowScope()); flowContext.getBeanFactory().registerScope("conversation", new ConversationScope()); // Ensure the current ClassLoader is used, or otherwise setting the ResourceLoader would suppress it ClassLoader classLoaderToUse = flowContext.getClassLoader(); flowContext.setClassLoader(classLoaderToUse); Resource flowResource = flowModelHolder.getFlowModelResource(); flowContext.setResourceLoader(new FlowRelativeResourceLoader(flowResource)); AnnotationConfigUtils.registerAnnotationConfigProcessors(flowContext); new XmlBeanDefinitionReader(flowContext).loadBeanDefinitions(resources); registerFlowBeans(flowContext.getBeanFactory()); registerMessageSource(flowContext, flowResource); flowContext.refresh(); return flowContext; }