use of org.springframework.beans.factory.support.DefaultListableBeanFactory in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method testGetBeanByTypeFiltersOutNonAutowireCandidates.
@Test
public void testGetBeanByTypeFiltersOutNonAutowireCandidates() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
RootBeanDefinition bd1 = new RootBeanDefinition(TestBean.class);
RootBeanDefinition bd2 = new RootBeanDefinition(TestBean.class);
RootBeanDefinition na1 = new RootBeanDefinition(TestBean.class);
na1.setAutowireCandidate(false);
lbf.registerBeanDefinition("bd1", bd1);
lbf.registerBeanDefinition("na1", na1);
// na1 was filtered
TestBean actual = lbf.getBean(TestBean.class);
assertSame(lbf.getBean("bd1", TestBean.class), actual);
lbf.registerBeanDefinition("bd2", bd2);
try {
lbf.getBean(TestBean.class);
fail("Should have thrown NoSuchBeanDefinitionException");
} catch (NoSuchBeanDefinitionException ex) {
// expected
}
}
use of org.springframework.beans.factory.support.DefaultListableBeanFactory in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method testConfigureBeanWithAutowiring.
@Test
public void testConfigureBeanWithAutowiring() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
lbf.registerBeanDefinition("spouse", bd);
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("age", "99");
RootBeanDefinition tbd = new RootBeanDefinition(TestBean.class);
tbd.setAutowireMode(RootBeanDefinition.AUTOWIRE_BY_NAME);
lbf.registerBeanDefinition("test", tbd);
TestBean tb = new TestBean();
lbf.configureBean(tb, "test");
assertSame(lbf, tb.getBeanFactory());
TestBean spouse = (TestBean) lbf.getBean("spouse");
assertEquals(spouse, tb.getSpouse());
}
use of org.springframework.beans.factory.support.DefaultListableBeanFactory in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method testAutowireBeanByTypePrimaryTakesPrecedenceOverPriority.
@Test
public void testAutowireBeanByTypePrimaryTakesPrecedenceOverPriority() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
lbf.setDependencyComparator(AnnotationAwareOrderComparator.INSTANCE);
RootBeanDefinition bd = new RootBeanDefinition(HighPriorityTestBean.class);
RootBeanDefinition bd2 = new RootBeanDefinition(TestBean.class);
bd2.setPrimary(true);
lbf.registerBeanDefinition("test", bd);
lbf.registerBeanDefinition("spouse", bd2);
DependenciesBean bean = (DependenciesBean) lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
assertThat(bean.getSpouse(), equalTo(lbf.getBean("spouse")));
}
use of org.springframework.beans.factory.support.DefaultListableBeanFactory in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method testAutowireBeanByTypeWithNoDependencyCheck.
@Test
public void testAutowireBeanByTypeWithNoDependencyCheck() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
DependenciesBean bean = (DependenciesBean) lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);
assertNull(bean.getSpouse());
}
use of org.springframework.beans.factory.support.DefaultListableBeanFactory in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method testAliasCircle.
@Test
public void testAliasCircle() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
lbf.registerAlias("test", "test2");
lbf.registerAlias("test2", "test3");
try {
lbf.registerAlias("test3", "test2");
fail("Should have thrown IllegalStateException");
} catch (IllegalStateException ex) {
// expected
}
try {
lbf.registerAlias("test3", "test");
fail("Should have thrown IllegalStateException");
} catch (IllegalStateException ex) {
// expected
}
lbf.registerAlias("test", "test3");
}
Aggregations