List of usage examples for org.springframework.context.support StaticApplicationContext setParent
@Override public void setParent(@Nullable ApplicationContext parent)
From source file:io.nuun.plugin.spring.UsingSpringAsDIPlugin.java
public Object nativeUnitModule() { ClassPathXmlApplicationContext parentCtx = new ClassPathXmlApplicationContext("context.xml"); StaticApplicationContext dynCtx = new StaticApplicationContext(); GenericBeanDefinition beanDef = new GenericBeanDefinition(); beanDef.setBeanClass(Service3Internal.class); beanDef.setScope("prototype"); dynCtx.registerBeanDefinition("service3", beanDef); dynCtx.setParent(parentCtx); dynCtx.refresh();//from w w w .j av a 2 s . c o m return dynCtx; }
From source file:org.nuunframework.spring.UsingSpringAsDIPlugin.java
@Override public Object dependencyInjectionDef() { ClassPathXmlApplicationContext parentCtx = new ClassPathXmlApplicationContext("context.xml"); StaticApplicationContext dynCtx = new StaticApplicationContext(); GenericBeanDefinition beanDef = new GenericBeanDefinition(); beanDef.setBeanClass(Service3Internal.class); beanDef.setScope("prototype"); dynCtx.registerBeanDefinition("service3", beanDef); dynCtx.setParent(parentCtx); dynCtx.refresh();// w w w.j av a 2s . c om return dynCtx; }
From source file:ome.client.utests.Preferences3Test.java
@Test(groups = "ticket:1058") public void testOmeroUserIsProperlySetWithSpring2_5_5Manual() { Server s = new Server("localhost", 1099); Login l = new Login("me", "password"); Properties p = s.asProperties(); p.putAll(l.asProperties());// ww w . j a v a 2s . c o m // This is copied from OmeroContext. This is the parent context which // should contain the properties; Properties copy = new Properties(p); ConstructorArgumentValues ctorArg1 = new ConstructorArgumentValues(); ctorArg1.addGenericArgumentValue(copy); BeanDefinition definition1 = new RootBeanDefinition(Properties.class, ctorArg1, null); StaticApplicationContext staticContext = new StaticApplicationContext(); staticContext.registerBeanDefinition("properties", definition1); staticContext.refresh(); // This is the child context and contains a definition of a // PlaceHolderConfigurer // as well as a user of StaticApplicationContext childContext = new StaticApplicationContext(); MutablePropertyValues mpv2 = new MutablePropertyValues(); mpv2.addPropertyValue("properties", new RuntimeBeanReference("properties")); mpv2.addPropertyValue("systemPropertiesModeName", "SYSTEM_PROPERTIES_MODE_FALLBACK"); mpv2.addPropertyValue("localOverride", "true"); BeanDefinition definitionConfigurer = new RootBeanDefinition(PreferencesPlaceholderConfigurer.class, null, mpv2); childContext.registerBeanDefinition("propertiesPlaceholderConfigurer", definitionConfigurer); ConstructorArgumentValues cav2 = new ConstructorArgumentValues(); cav2.addGenericArgumentValue("${omero.user}"); BeanDefinition definitionTest = new RootBeanDefinition(String.class, cav2, null); childContext.registerBeanDefinition("test", definitionTest); childContext.setParent(staticContext); childContext.refresh(); String test = (String) childContext.getBean("test"); assertEquals(test, "me"); }