|
|
|
@ -699,8 +699,7 @@ public class AutowiredAnnotationBeanPostProcessorTests { |
|
|
|
AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); |
|
|
|
AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); |
|
|
|
bpp.setBeanFactory(bf); |
|
|
|
bpp.setBeanFactory(bf); |
|
|
|
bf.addBeanPostProcessor(bpp); |
|
|
|
bf.addBeanPostProcessor(bpp); |
|
|
|
bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition( |
|
|
|
bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(ConstructorsCollectionResourceInjectionBean.class)); |
|
|
|
ConstructorsCollectionResourceInjectionBean.class)); |
|
|
|
|
|
|
|
TestBean tb = new TestBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
bf.registerSingleton("testBean", tb); |
|
|
|
bf.registerSingleton("testBean", tb); |
|
|
|
FixedOrder2NestedTestBean ntb1 = new FixedOrder2NestedTestBean(); |
|
|
|
FixedOrder2NestedTestBean ntb1 = new FixedOrder2NestedTestBean(); |
|
|
|
@ -717,6 +716,46 @@ public class AutowiredAnnotationBeanPostProcessorTests { |
|
|
|
bf.destroySingletons(); |
|
|
|
bf.destroySingletons(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void testSingleConstructorInjectionWithMultipleCandidatesAsOrderedCollection() { |
|
|
|
|
|
|
|
DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); |
|
|
|
|
|
|
|
bf.setDependencyComparator(AnnotationAwareOrderComparator.INSTANCE); |
|
|
|
|
|
|
|
AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); |
|
|
|
|
|
|
|
bpp.setBeanFactory(bf); |
|
|
|
|
|
|
|
bf.addBeanPostProcessor(bpp); |
|
|
|
|
|
|
|
bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(SingleConstructorCollectionInjectionBean.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); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SingleConstructorCollectionInjectionBean bean = (SingleConstructorCollectionInjectionBean) bf.getBean("annotatedBean"); |
|
|
|
|
|
|
|
assertSame(tb, bean.getTestBean()); |
|
|
|
|
|
|
|
assertEquals(2, bean.getNestedTestBeans().size()); |
|
|
|
|
|
|
|
assertSame(ntb2, bean.getNestedTestBeans().get(0)); |
|
|
|
|
|
|
|
assertSame(ntb1, bean.getNestedTestBeans().get(1)); |
|
|
|
|
|
|
|
bf.destroySingletons(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void testSingleConstructorInjectionWithEmptyCollection() { |
|
|
|
|
|
|
|
DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); |
|
|
|
|
|
|
|
bf.setAutowireCandidateResolver(new QualifierAnnotationAutowireCandidateResolver()); |
|
|
|
|
|
|
|
AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); |
|
|
|
|
|
|
|
bpp.setBeanFactory(bf); |
|
|
|
|
|
|
|
bf.addBeanPostProcessor(bpp); |
|
|
|
|
|
|
|
bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(SingleConstructorCollectionInjectionBean.class)); |
|
|
|
|
|
|
|
TestBean tb = new TestBean(); |
|
|
|
|
|
|
|
bf.registerSingleton("testBean", tb); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SingleConstructorCollectionInjectionBean bean = (SingleConstructorCollectionInjectionBean) bf.getBean("annotatedBean"); |
|
|
|
|
|
|
|
assertSame(tb, bean.getTestBean()); |
|
|
|
|
|
|
|
assertNull(bean.getNestedTestBeans()); |
|
|
|
|
|
|
|
bf.destroySingletons(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testConstructorResourceInjectionWithMultipleCandidatesAndFallback() { |
|
|
|
public void testConstructorResourceInjectionWithMultipleCandidatesAndFallback() { |
|
|
|
DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); |
|
|
|
DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); |
|
|
|
@ -2757,6 +2796,28 @@ public class AutowiredAnnotationBeanPostProcessorTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static class SingleConstructorCollectionInjectionBean { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private ITestBean testBean; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<NestedTestBean> nestedTestBeans; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public SingleConstructorCollectionInjectionBean(ITestBean testBean, |
|
|
|
|
|
|
|
@Autowired(required = false) List<NestedTestBean> nestedTestBeans) { |
|
|
|
|
|
|
|
this.testBean = testBean; |
|
|
|
|
|
|
|
this.nestedTestBeans = nestedTestBeans; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public ITestBean getTestBean() { |
|
|
|
|
|
|
|
return this.testBean; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public List<NestedTestBean> getNestedTestBeans() { |
|
|
|
|
|
|
|
return this.nestedTestBeans; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("serial") |
|
|
|
@SuppressWarnings("serial") |
|
|
|
public static class MyTestBeanMap extends LinkedHashMap<String, TestBean> { |
|
|
|
public static class MyTestBeanMap extends LinkedHashMap<String, TestBean> { |
|
|
|
} |
|
|
|
} |
|
|
|
|