@ -1077,15 +1077,29 @@ public class AutowiredAnnotationBeanPostProcessorTests {
@@ -1077,15 +1077,29 @@ public class AutowiredAnnotationBeanPostProcessorTests {
}
@Test
public void testObjectFactoryInjection ( ) {
public void testObjectFactoryField Injection ( ) {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory ( ) ;
AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor ( ) ;
bpp . setBeanFactory ( bf ) ;
bf . addBeanPostProcessor ( bpp ) ;
bf . registerBeanDefinition ( "annotatedBean" , new RootBeanDefinition ( ObjectFactoryInjectionBean . class ) ) ;
bf . registerBeanDefinition ( "annotatedBean" , new RootBeanDefinition ( ObjectFactoryField InjectionBean . class ) ) ;
bf . registerBeanDefinition ( "testBean" , new RootBeanDefinition ( TestBean . class ) ) ;
ObjectFactoryInjectionBean bean = ( ObjectFactoryInjectionBean ) bf . getBean ( "annotatedBean" ) ;
ObjectFactoryFieldInjectionBean bean = ( ObjectFactoryFieldInjectionBean ) bf . getBean ( "annotatedBean" ) ;
assertSame ( bf . getBean ( "testBean" ) , bean . getTestBean ( ) ) ;
bf . destroySingletons ( ) ;
}
@Test
public void testObjectFactoryConstructorInjection ( ) {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory ( ) ;
AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor ( ) ;
bpp . setBeanFactory ( bf ) ;
bf . addBeanPostProcessor ( bpp ) ;
bf . registerBeanDefinition ( "annotatedBean" , new RootBeanDefinition ( ObjectFactoryConstructorInjectionBean . class ) ) ;
bf . registerBeanDefinition ( "testBean" , new RootBeanDefinition ( TestBean . class ) ) ;
ObjectFactoryConstructorInjectionBean bean = ( ObjectFactoryConstructorInjectionBean ) bf . getBean ( "annotatedBean" ) ;
assertSame ( bf . getBean ( "testBean" ) , bean . getTestBean ( ) ) ;
bf . destroySingletons ( ) ;
}
@ -1096,14 +1110,14 @@ public class AutowiredAnnotationBeanPostProcessorTests {
@@ -1096,14 +1110,14 @@ public class AutowiredAnnotationBeanPostProcessorTests {
AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor ( ) ;
bpp . setBeanFactory ( bf ) ;
bf . addBeanPostProcessor ( bpp ) ;
RootBeanDefinition annotatedBeanDefinition = new RootBeanDefinition ( ObjectFactoryInjectionBean . class ) ;
RootBeanDefinition annotatedBeanDefinition = new RootBeanDefinition ( ObjectFactoryField InjectionBean . class ) ;
annotatedBeanDefinition . setScope ( BeanDefinition . SCOPE_PROTOTYPE ) ;
bf . registerBeanDefinition ( "annotatedBean" , annotatedBeanDefinition ) ;
bf . registerBeanDefinition ( "testBean" , new RootBeanDefinition ( TestBean . class ) ) ;
ObjectFactoryInjectionBean bean = ( ObjectFactoryInjectionBean ) bf . getBean ( "annotatedBean" ) ;
ObjectFactoryField InjectionBean bean = ( ObjectFactoryField InjectionBean ) bf . getBean ( "annotatedBean" ) ;
assertSame ( bf . getBean ( "testBean" ) , bean . getTestBean ( ) ) ;
ObjectFactoryInjectionBean anotherBean = ( ObjectFactoryInjectionBean ) bf . getBean ( "annotatedBean" ) ;
ObjectFactoryField InjectionBean anotherBean = ( ObjectFactoryField InjectionBean ) bf . getBean ( "annotatedBean" ) ;
assertNotSame ( anotherBean , bean ) ;
assertSame ( bf . getBean ( "testBean" ) , anotherBean . getTestBean ( ) ) ;
}
@ -1153,13 +1167,13 @@ public class AutowiredAnnotationBeanPostProcessorTests {
@@ -1153,13 +1167,13 @@ public class AutowiredAnnotationBeanPostProcessorTests {
AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor ( ) ;
bpp . setBeanFactory ( bf ) ;
bf . addBeanPostProcessor ( bpp ) ;
bf . registerBeanDefinition ( "annotatedBean" , new RootBeanDefinition ( ObjectFactoryInjectionBean . class ) ) ;
bf . registerBeanDefinition ( "annotatedBean" , new RootBeanDefinition ( ObjectFactoryField InjectionBean . class ) ) ;
bf . registerBeanDefinition ( "testBean" , new RootBeanDefinition ( TestBean . class ) ) ;
bf . setSerializationId ( "test" ) ;
ObjectFactoryInjectionBean bean = ( ObjectFactoryInjectionBean ) bf . getBean ( "annotatedBean" ) ;
ObjectFactoryField InjectionBean bean = ( ObjectFactoryField InjectionBean ) bf . getBean ( "annotatedBean" ) ;
assertSame ( bf . getBean ( "testBean" ) , bean . getTestBean ( ) ) ;
bean = ( ObjectFactoryInjectionBean ) SerializationTestUtils . serializeAndDeserialize ( bean ) ;
bean = ( ObjectFactoryField InjectionBean ) SerializationTestUtils . serializeAndDeserialize ( bean ) ;
assertSame ( bf . getBean ( "testBean" ) , bean . getTestBean ( ) ) ;
bf . destroySingletons ( ) ;
}
@ -2838,7 +2852,7 @@ public class AutowiredAnnotationBeanPostProcessorTests {
@@ -2838,7 +2852,7 @@ public class AutowiredAnnotationBeanPostProcessorTests {
@SuppressWarnings ( "serial" )
public static class ObjectFactoryInjectionBean implements Serializable {
public static class ObjectFactoryField InjectionBean implements Serializable {
@Autowired
private ObjectFactory < TestBean > testBeanFactory ;
@ -2849,6 +2863,21 @@ public class AutowiredAnnotationBeanPostProcessorTests {
@@ -2849,6 +2863,21 @@ public class AutowiredAnnotationBeanPostProcessorTests {
}
@SuppressWarnings ( "serial" )
public static class ObjectFactoryConstructorInjectionBean implements Serializable {
private final ObjectFactory < TestBean > testBeanFactory ;
public ObjectFactoryConstructorInjectionBean ( ObjectFactory < TestBean > testBeanFactory ) {
this . testBeanFactory = testBeanFactory ;
}
public TestBean getTestBean ( ) {
return this . testBeanFactory . getObject ( ) ;
}
}
public static class ObjectFactoryQualifierInjectionBean {
@Autowired