use of org.springframework.beans.factory.support.ChildBeanDefinition in project hudson-2.x by hudson.
the class DefaultBeanConfiguration method createBeanDefinition.
protected AbstractBeanDefinition createBeanDefinition() {
AbstractBeanDefinition bd;
if (constructorArgs.size() > 0) {
ConstructorArgumentValues cav = new ConstructorArgumentValues();
for (Object constructorArg : constructorArgs) {
cav.addGenericArgumentValue(constructorArg);
}
if (StringUtils.isBlank(parentName)) {
bd = new RootBeanDefinition(clazz, cav, null);
} else {
bd = new ChildBeanDefinition(parentName, clazz, cav, null);
}
bd.setSingleton(singleton);
} else {
if (StringUtils.isBlank(parentName)) {
bd = new RootBeanDefinition(clazz, singleton);
} else {
bd = new ChildBeanDefinition(parentName, clazz, null, null);
bd.setSingleton(singleton);
}
}
wrapper = new BeanWrapperImpl(bd);
return bd;
}
use of org.springframework.beans.factory.support.ChildBeanDefinition in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method testScopeInheritanceForChildBeanDefinitions.
@Test
public void testScopeInheritanceForChildBeanDefinitions() throws Exception {
RootBeanDefinition parent = new RootBeanDefinition();
parent.setScope("bonanza!");
AbstractBeanDefinition child = new ChildBeanDefinition("parent");
child.setBeanClass(TestBean.class);
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
factory.registerBeanDefinition("parent", parent);
factory.registerBeanDefinition("child", child);
BeanDefinition def = factory.getMergedBeanDefinition("child");
assertEquals("Child 'scope' not inherited", "bonanza!", def.getScope());
}
use of org.springframework.beans.factory.support.ChildBeanDefinition in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method testGetTypeWorksAfterParentChildMerging.
@Test
public void testGetTypeWorksAfterParentChildMerging() {
RootBeanDefinition parentDefinition = new RootBeanDefinition(TestBean.class);
ChildBeanDefinition childDefinition = new ChildBeanDefinition("parent", DerivedTestBean.class, null, null);
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
factory.registerBeanDefinition("parent", parentDefinition);
factory.registerBeanDefinition("child", childDefinition);
factory.freezeConfiguration();
assertEquals(TestBean.class, factory.getType("parent"));
assertEquals(DerivedTestBean.class, factory.getType("child"));
}
use of org.springframework.beans.factory.support.ChildBeanDefinition in project spring-framework by spring-projects.
the class ConfigurationClassPostProcessorTests method postProcessorIntrospectsInheritedDefinitionsCorrectly.
/**
* Tests whether a bean definition without a specified bean class is handled correctly.
*/
@Test
void postProcessorIntrospectsInheritedDefinitionsCorrectly() {
beanFactory.registerBeanDefinition("config", new RootBeanDefinition(SingletonBeanConfig.class));
beanFactory.registerBeanDefinition("parent", new RootBeanDefinition(TestBean.class));
beanFactory.registerBeanDefinition("child", new ChildBeanDefinition("parent"));
ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
pp.postProcessBeanFactory(beanFactory);
Foo foo = beanFactory.getBean("foo", Foo.class);
Bar bar = beanFactory.getBean("bar", Bar.class);
assertThat(bar.foo).isSameAs(foo);
}
use of org.springframework.beans.factory.support.ChildBeanDefinition in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method getTypeWorksAfterParentChildMerging.
@Test
void getTypeWorksAfterParentChildMerging() {
RootBeanDefinition parentDefinition = new RootBeanDefinition(TestBean.class);
ChildBeanDefinition childDefinition = new ChildBeanDefinition("parent", DerivedTestBean.class, null, null);
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
factory.registerBeanDefinition("parent", parentDefinition);
factory.registerBeanDefinition("child", childDefinition);
factory.freezeConfiguration();
assertThat(factory.getType("parent")).isEqualTo(TestBean.class);
assertThat(factory.getType("child")).isEqualTo(DerivedTestBean.class);
}
Aggregations