Search in sources :

Example 1 with ConstructorDependenciesBean

use of org.springframework.beans.factory.xml.ConstructorDependenciesBean in project spring-framework by spring-projects.

the class DefaultListableBeanFactoryTests method testAutowireConstructor.

@Test
public void testAutowireConstructor() {
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
    lbf.registerBeanDefinition("spouse", bd);
    ConstructorDependenciesBean bean = (ConstructorDependenciesBean) lbf.autowire(ConstructorDependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, true);
    Object spouse = lbf.getBean("spouse");
    assertTrue(bean.getSpouse1() == spouse);
    assertTrue(BeanFactoryUtils.beanOfType(lbf, TestBean.class) == spouse);
}
Also used : DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) ConstructorDependenciesBean(org.springframework.beans.factory.xml.ConstructorDependenciesBean) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) Test(org.junit.Test)

Example 2 with ConstructorDependenciesBean

use of org.springframework.beans.factory.xml.ConstructorDependenciesBean in project spring-framework by spring-projects.

the class DefaultListableBeanFactoryTests method autowireConstructor.

@Test
void autowireConstructor() {
    RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
    lbf.registerBeanDefinition("spouse", bd);
    ConstructorDependenciesBean bean = (ConstructorDependenciesBean) lbf.autowire(ConstructorDependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, true);
    Object spouse = lbf.getBean("spouse");
    assertThat(bean.getSpouse1() == spouse).isTrue();
    assertThat(BeanFactoryUtils.beanOfType(lbf, TestBean.class) == spouse).isTrue();
}
Also used : DerivedTestBean(org.springframework.beans.testfixture.beans.DerivedTestBean) NestedTestBean(org.springframework.beans.testfixture.beans.NestedTestBean) TestBean(org.springframework.beans.testfixture.beans.TestBean) ITestBean(org.springframework.beans.testfixture.beans.ITestBean) ConstructorDependenciesBean(org.springframework.beans.factory.xml.ConstructorDependenciesBean) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) Test(org.junit.jupiter.api.Test)

Aggregations

RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)2 ConstructorDependenciesBean (org.springframework.beans.factory.xml.ConstructorDependenciesBean)2 Test (org.junit.Test)1 Test (org.junit.jupiter.api.Test)1 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)1 DerivedTestBean (org.springframework.beans.testfixture.beans.DerivedTestBean)1 ITestBean (org.springframework.beans.testfixture.beans.ITestBean)1 NestedTestBean (org.springframework.beans.testfixture.beans.NestedTestBean)1 TestBean (org.springframework.beans.testfixture.beans.TestBean)1