Search in sources :

Example 1 with ChildBeanDefinition

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;
}
Also used : AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) BeanWrapperImpl(org.springframework.beans.BeanWrapperImpl) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) ChildBeanDefinition(org.springframework.beans.factory.support.ChildBeanDefinition) ConstructorArgumentValues(org.springframework.beans.factory.config.ConstructorArgumentValues)

Example 2 with ChildBeanDefinition

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());
}
Also used : AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) ChildBeanDefinition(org.springframework.beans.factory.support.ChildBeanDefinition) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) ChildBeanDefinition(org.springframework.beans.factory.support.ChildBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) Test(org.junit.Test)

Example 3 with ChildBeanDefinition

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"));
}
Also used : DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) ChildBeanDefinition(org.springframework.beans.factory.support.ChildBeanDefinition) Test(org.junit.Test)

Example 4 with ChildBeanDefinition

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);
}
Also used : TestBean(org.springframework.beans.testfixture.beans.TestBean) ITestBean(org.springframework.beans.testfixture.beans.ITestBean) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) ChildBeanDefinition(org.springframework.beans.factory.support.ChildBeanDefinition) Test(org.junit.jupiter.api.Test)

Example 5 with ChildBeanDefinition

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);
}
Also used : DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) ChildBeanDefinition(org.springframework.beans.factory.support.ChildBeanDefinition) Test(org.junit.jupiter.api.Test)

Aggregations

ChildBeanDefinition (org.springframework.beans.factory.support.ChildBeanDefinition)9 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)9 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)6 Test (org.junit.jupiter.api.Test)4 AbstractBeanDefinition (org.springframework.beans.factory.support.AbstractBeanDefinition)4 Test (org.junit.Test)3 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)3 TestBean (org.springframework.beans.testfixture.beans.TestBean)3 ITestBean (org.springframework.beans.testfixture.beans.ITestBean)2 Properties (java.util.Properties)1 BeanWrapperImpl (org.springframework.beans.BeanWrapperImpl)1 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)1 ConstructorArgumentValues (org.springframework.beans.factory.config.ConstructorArgumentValues)1 DerivedTestBean (org.springframework.beans.testfixture.beans.DerivedTestBean)1 IndexedTestBean (org.springframework.beans.testfixture.beans.IndexedTestBean)1 NestedTestBean (org.springframework.beans.testfixture.beans.NestedTestBean)1 DerivedTestBean (org.springframework.tests.sample.beans.DerivedTestBean)1 ITestBean (org.springframework.tests.sample.beans.ITestBean)1 NestedTestBean (org.springframework.tests.sample.beans.NestedTestBean)1 TestBean (org.springframework.tests.sample.beans.TestBean)1