|
|
|
@ -25,6 +25,7 @@ import java.lang.reflect.InvocationHandler; |
|
|
|
import java.lang.reflect.Method; |
|
|
|
import java.lang.reflect.Method; |
|
|
|
import java.lang.reflect.Proxy; |
|
|
|
import java.lang.reflect.Proxy; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.Collections; |
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.HashSet; |
|
|
|
import java.util.HashSet; |
|
|
|
import java.util.LinkedHashMap; |
|
|
|
import java.util.LinkedHashMap; |
|
|
|
import java.util.LinkedHashSet; |
|
|
|
import java.util.LinkedHashSet; |
|
|
|
@ -910,16 +911,15 @@ public class AutowiredAnnotationBeanPostProcessorTests { |
|
|
|
RootBeanDefinition bd = new RootBeanDefinition(MapConstructorInjectionBean.class); |
|
|
|
RootBeanDefinition bd = new RootBeanDefinition(MapConstructorInjectionBean.class); |
|
|
|
bd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE); |
|
|
|
bd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE); |
|
|
|
bf.registerBeanDefinition("annotatedBean", bd); |
|
|
|
bf.registerBeanDefinition("annotatedBean", bd); |
|
|
|
Map<String, TestBean> tbm = new LinkedHashMap<String, TestBean>(); |
|
|
|
RootBeanDefinition tbm = new RootBeanDefinition(CollectionFactoryMethods.class); |
|
|
|
tbm.put("testBean1", new TestBean("tb1")); |
|
|
|
tbm.setUniqueFactoryMethodName("testBeanMap"); |
|
|
|
tbm.put("testBean2", new TestBean("tb2")); |
|
|
|
bf.registerBeanDefinition("myTestBeanMap", tbm); |
|
|
|
bf.registerSingleton("testBeans", tbm); |
|
|
|
bf.registerSingleton("otherMap", new HashMap<Object, Object>()); |
|
|
|
bf.registerSingleton("otherMap", new Properties()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MapConstructorInjectionBean bean = (MapConstructorInjectionBean) bf.getBean("annotatedBean"); |
|
|
|
MapConstructorInjectionBean bean = (MapConstructorInjectionBean) bf.getBean("annotatedBean"); |
|
|
|
assertSame(tbm, bean.getTestBeanMap()); |
|
|
|
assertSame(bf.getBean("myTestBeanMap"), bean.getTestBeanMap()); |
|
|
|
bean = (MapConstructorInjectionBean) bf.getBean("annotatedBean"); |
|
|
|
bean = (MapConstructorInjectionBean) bf.getBean("annotatedBean"); |
|
|
|
assertSame(tbm, bean.getTestBeanMap()); |
|
|
|
assertSame(bf.getBean("myTestBeanMap"), bean.getTestBeanMap()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@ -954,16 +954,15 @@ public class AutowiredAnnotationBeanPostProcessorTests { |
|
|
|
RootBeanDefinition bd = new RootBeanDefinition(SetConstructorInjectionBean.class); |
|
|
|
RootBeanDefinition bd = new RootBeanDefinition(SetConstructorInjectionBean.class); |
|
|
|
bd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE); |
|
|
|
bd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE); |
|
|
|
bf.registerBeanDefinition("annotatedBean", bd); |
|
|
|
bf.registerBeanDefinition("annotatedBean", bd); |
|
|
|
Set<TestBean> tbs = new LinkedHashSet<TestBean>(); |
|
|
|
RootBeanDefinition tbs = new RootBeanDefinition(CollectionFactoryMethods.class); |
|
|
|
tbs.add(new TestBean("tb1")); |
|
|
|
tbs.setUniqueFactoryMethodName("testBeanSet"); |
|
|
|
tbs.add(new TestBean("tb2")); |
|
|
|
bf.registerBeanDefinition("myTestBeanSet", tbs); |
|
|
|
bf.registerSingleton("testBeanSet", tbs); |
|
|
|
|
|
|
|
bf.registerSingleton("otherSet", new HashSet<Object>()); |
|
|
|
bf.registerSingleton("otherSet", new HashSet<Object>()); |
|
|
|
|
|
|
|
|
|
|
|
SetConstructorInjectionBean bean = (SetConstructorInjectionBean) bf.getBean("annotatedBean"); |
|
|
|
SetConstructorInjectionBean bean = (SetConstructorInjectionBean) bf.getBean("annotatedBean"); |
|
|
|
assertSame(tbs, bean.getTestBeanSet()); |
|
|
|
assertSame(bf.getBean("myTestBeanSet"), bean.getTestBeanSet()); |
|
|
|
bean = (SetConstructorInjectionBean) bf.getBean("annotatedBean"); |
|
|
|
bean = (SetConstructorInjectionBean) bf.getBean("annotatedBean"); |
|
|
|
assertSame(tbs, bean.getTestBeanSet()); |
|
|
|
assertSame(bf.getBean("myTestBeanSet"), bean.getTestBeanSet()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@ -3203,4 +3202,23 @@ public class AutowiredAnnotationBeanPostProcessorTests { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static class CollectionFactoryMethods { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static Map<String, TestBean> testBeanMap() { |
|
|
|
|
|
|
|
Map<String, TestBean> tbm = new LinkedHashMap<String, TestBean>(); |
|
|
|
|
|
|
|
tbm.put("testBean1", new TestBean("tb1")); |
|
|
|
|
|
|
|
tbm.put("testBean2", new TestBean("tb2")); |
|
|
|
|
|
|
|
return tbm; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static Set<TestBean> testBeanSet() { |
|
|
|
|
|
|
|
Set<TestBean> tbs = new LinkedHashSet<TestBean>(); |
|
|
|
|
|
|
|
tbs.add(new TestBean("tb1")); |
|
|
|
|
|
|
|
tbs.add(new TestBean("tb2")); |
|
|
|
|
|
|
|
return tbs; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|