use of org.springframework.beans.factory.support.DefaultListableBeanFactory in project spring-framework by spring-projects.
the class AutowiredAnnotationBeanPostProcessorTests method testIncompleteBeanDefinition.
@Test
public void testIncompleteBeanDefinition() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
bpp.setBeanFactory(bf);
bf.addBeanPostProcessor(bpp);
bf.registerBeanDefinition("testBean", new GenericBeanDefinition());
try {
bf.getBean("testBean");
fail("Should have thrown BeanCreationException");
} catch (BeanCreationException ex) {
assertTrue(ex.getRootCause() instanceof IllegalStateException);
}
}
use of org.springframework.beans.factory.support.DefaultListableBeanFactory in project spring-framework by spring-projects.
the class AutowiredAnnotationBeanPostProcessorTests method testConstructorResourceInjectionWithMultipleOrderedCandidates.
@Test
public void testConstructorResourceInjectionWithMultipleOrderedCandidates() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.setDependencyComparator(AnnotationAwareOrderComparator.INSTANCE);
AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
bpp.setBeanFactory(bf);
bf.addBeanPostProcessor(bpp);
bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(ConstructorsResourceInjectionBean.class));
TestBean tb = new TestBean();
bf.registerSingleton("testBean", tb);
FixedOrder2NestedTestBean ntb1 = new FixedOrder2NestedTestBean();
bf.registerSingleton("nestedTestBean1", ntb1);
FixedOrder1NestedTestBean ntb2 = new FixedOrder1NestedTestBean();
bf.registerSingleton("nestedTestBean2", ntb2);
ConstructorsResourceInjectionBean bean = (ConstructorsResourceInjectionBean) bf.getBean("annotatedBean");
assertNull(bean.getTestBean3());
assertSame(tb, bean.getTestBean4());
assertEquals(2, bean.getNestedTestBeans().length);
assertSame(ntb2, bean.getNestedTestBeans()[0]);
assertSame(ntb1, bean.getNestedTestBeans()[1]);
bf.destroySingletons();
}
use of org.springframework.beans.factory.support.DefaultListableBeanFactory in project spring-framework by spring-projects.
the class AutowiredAnnotationBeanPostProcessorTests method testGenericsBasedConstructorInjection.
@Test
public void testGenericsBasedConstructorInjection() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.setAutowireCandidateResolver(new QualifierAnnotationAutowireCandidateResolver());
AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
bpp.setBeanFactory(bf);
bf.addBeanPostProcessor(bpp);
RootBeanDefinition bd = new RootBeanDefinition(RepositoryConstructorInjectionBean.class);
bd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
bf.registerBeanDefinition("annotatedBean", bd);
StringRepository sr = new StringRepository();
bf.registerSingleton("stringRepo", sr);
IntegerRepository ir = new IntegerRepository();
bf.registerSingleton("integerRepo", ir);
RepositoryConstructorInjectionBean bean = (RepositoryConstructorInjectionBean) bf.getBean("annotatedBean");
assertSame(sr, bean.stringRepository);
assertSame(ir, bean.integerRepository);
assertSame(1, bean.stringRepositoryArray.length);
assertSame(1, bean.integerRepositoryArray.length);
assertSame(sr, bean.stringRepositoryArray[0]);
assertSame(ir, bean.integerRepositoryArray[0]);
assertSame(1, bean.stringRepositoryList.size());
assertSame(1, bean.integerRepositoryList.size());
assertSame(sr, bean.stringRepositoryList.get(0));
assertSame(ir, bean.integerRepositoryList.get(0));
assertSame(1, bean.stringRepositoryMap.size());
assertSame(1, bean.integerRepositoryMap.size());
assertSame(sr, bean.stringRepositoryMap.get("stringRepo"));
assertSame(ir, bean.integerRepositoryMap.get("integerRepo"));
}
use of org.springframework.beans.factory.support.DefaultListableBeanFactory in project spring-framework by spring-projects.
the class AutowiredAnnotationBeanPostProcessorTests method testCircularTypeReference.
@Test
public void testCircularTypeReference() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.setAutowireCandidateResolver(new QualifierAnnotationAutowireCandidateResolver());
AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
bpp.setBeanFactory(bf);
bf.addBeanPostProcessor(bpp);
bf.registerBeanDefinition("bean1", new RootBeanDefinition(StockServiceImpl.class));
bf.registerBeanDefinition("bean2", new RootBeanDefinition(StockMovementDaoImpl.class));
bf.registerBeanDefinition("bean3", new RootBeanDefinition(StockMovementImpl.class));
bf.registerBeanDefinition("bean4", new RootBeanDefinition(StockMovementInstructionImpl.class));
StockServiceImpl service = bf.getBean(StockServiceImpl.class);
assertSame(bf.getBean(StockMovementDaoImpl.class), service.stockMovementDao);
}
use of org.springframework.beans.factory.support.DefaultListableBeanFactory in project spring-framework by spring-projects.
the class AutowiredAnnotationBeanPostProcessorTests method testGenericsBasedFactoryBeanInjectionWithBeanDefinition.
@Test
public void testGenericsBasedFactoryBeanInjectionWithBeanDefinition() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.setAutowireCandidateResolver(new QualifierAnnotationAutowireCandidateResolver());
AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
bpp.setBeanFactory(bf);
bf.addBeanPostProcessor(bpp);
RootBeanDefinition bd = new RootBeanDefinition(RepositoryFactoryBeanInjectionBean.class);
bd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
bf.registerBeanDefinition("annotatedBean", bd);
bf.registerBeanDefinition("repoFactoryBean", new RootBeanDefinition(RepositoryFactoryBean.class));
RepositoryFactoryBeanInjectionBean bean = (RepositoryFactoryBeanInjectionBean) bf.getBean("annotatedBean");
RepositoryFactoryBean<?> repoFactoryBean = bf.getBean("&repoFactoryBean", RepositoryFactoryBean.class);
assertSame(repoFactoryBean, bean.repositoryFactoryBean);
}
Aggregations