16
16
17
17
package org .springframework .context .annotation ;
18
18
19
- import java .util .Collections ;
20
19
import java .util .Map ;
21
- import java .util .Set ;
22
20
import java .util .regex .Pattern ;
23
21
24
22
import org .junit .jupiter .api .Test ;
@@ -400,44 +398,66 @@ void individualBeanWithFactoryBeanSupplierAndTargetType() {
400
398
void individualBeanWithFactoryBeanTypeAsTargetType () {
401
399
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext ();
402
400
RootBeanDefinition bd1 = new RootBeanDefinition ();
403
- bd1 .setBeanClass (SetFactoryBean .class );
404
- bd1 .setTargetType (ResolvableType .forClassWithGenerics (FactoryBean .class , ResolvableType .forClassWithGenerics (Set .class , String .class )));
401
+ bd1 .setBeanClass (GenericHolderFactoryBean .class );
402
+ bd1 .setTargetType (ResolvableType .forClassWithGenerics (FactoryBean .class , ResolvableType .forClassWithGenerics (GenericHolder .class , String .class )));
405
403
bd1 .setLazyInit (true );
406
404
context .registerBeanDefinition ("fb1" , bd1 );
407
405
RootBeanDefinition bd2 = new RootBeanDefinition ();
408
406
bd2 .setBeanClass (UntypedFactoryBean .class );
409
- bd2 .setTargetType (ResolvableType .forClassWithGenerics (FactoryBean .class , ResolvableType .forClassWithGenerics (Set .class , Integer .class )));
407
+ bd2 .setTargetType (ResolvableType .forClassWithGenerics (FactoryBean .class , ResolvableType .forClassWithGenerics (GenericHolder .class , Integer .class )));
410
408
bd2 .setLazyInit (true );
411
409
context .registerBeanDefinition ("fb2" , bd2 );
412
410
context .registerBeanDefinition ("ip" , new RootBeanDefinition (FactoryBeanInjectionPoints .class ));
413
411
context .refresh ();
414
412
415
- assertThat (context .getType ("&fb1" )).isEqualTo (SetFactoryBean .class );
416
- assertThat (context .getType ("fb1" )).isEqualTo (Set .class );
413
+ assertThat (context .getType ("&fb1" )).isEqualTo (GenericHolderFactoryBean .class );
414
+ assertThat (context .getType ("fb1" )).isEqualTo (GenericHolder .class );
417
415
assertThat (context .getBeanNamesForType (FactoryBean .class )).hasSize (2 );
418
- assertThat (context .getBeanNamesForType (SetFactoryBean .class )).hasSize (1 );
416
+ assertThat (context .getBeanNamesForType (GenericHolderFactoryBean .class )).hasSize (1 );
419
417
assertThat (context .getBean ("ip" , FactoryBeanInjectionPoints .class ).factoryBean ).isSameAs (context .getBean ("&fb1" ));
420
418
assertThat (context .getBean ("ip" , FactoryBeanInjectionPoints .class ).factoryResult ).isSameAs (context .getBean ("fb1" ));
421
419
}
422
420
421
+ @ Test
422
+ void individualBeanWithUnresolvedFactoryBeanTypeAsTargetType () {
423
+ AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext ();
424
+ RootBeanDefinition bd1 = new RootBeanDefinition ();
425
+ bd1 .setBeanClass (GenericHolderFactoryBean .class );
426
+ bd1 .setTargetType (ResolvableType .forClassWithGenerics (FactoryBean .class , ResolvableType .forClassWithGenerics (GenericHolder .class , Object .class )));
427
+ bd1 .setLazyInit (true );
428
+ context .registerBeanDefinition ("fb1" , bd1 );
429
+ RootBeanDefinition bd2 = new RootBeanDefinition ();
430
+ bd2 .setBeanClass (UntypedFactoryBean .class );
431
+ bd2 .setTargetType (ResolvableType .forClassWithGenerics (FactoryBean .class , ResolvableType .forClassWithGenerics (GenericHolder .class , Integer .class )));
432
+ bd2 .setLazyInit (true );
433
+ context .registerBeanDefinition ("fb2" , bd2 );
434
+ context .registerBeanDefinition ("ip" , new RootBeanDefinition (FactoryResultInjectionPoint .class ));
435
+ context .refresh ();
436
+
437
+ assertThat (context .getType ("&fb1" )).isEqualTo (GenericHolderFactoryBean .class );
438
+ assertThat (context .getType ("fb1" )).isEqualTo (GenericHolder .class );
439
+ assertThat (context .getBeanNamesForType (FactoryBean .class )).hasSize (2 );
440
+ assertThat (context .getBean ("ip" , FactoryResultInjectionPoint .class ).factoryResult ).isSameAs (context .getBean ("fb1" ));
441
+ }
442
+
423
443
@ Test
424
444
void individualBeanWithFactoryBeanObjectTypeAsTargetType () {
425
445
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext ();
426
446
RootBeanDefinition bd1 = new RootBeanDefinition ();
427
- bd1 .setBeanClass (SetFactoryBean .class );
428
- bd1 .setTargetType (ResolvableType .forClassWithGenerics (Set .class , String .class ));
447
+ bd1 .setBeanClass (GenericHolderFactoryBean .class );
448
+ bd1 .setTargetType (ResolvableType .forClassWithGenerics (GenericHolder .class , String .class ));
429
449
context .registerBeanDefinition ("fb1" , bd1 );
430
450
RootBeanDefinition bd2 = new RootBeanDefinition ();
431
451
bd2 .setBeanClass (UntypedFactoryBean .class );
432
- bd2 .setTargetType (ResolvableType .forClassWithGenerics (Set .class , Integer .class ));
452
+ bd2 .setTargetType (ResolvableType .forClassWithGenerics (GenericHolder .class , Integer .class ));
433
453
context .registerBeanDefinition ("fb2" , bd2 );
434
454
context .registerBeanDefinition ("ip" , new RootBeanDefinition (FactoryResultInjectionPoint .class ));
435
455
context .refresh ();
436
456
437
- assertThat (context .getType ("&fb1" )).isEqualTo (SetFactoryBean .class );
438
- assertThat (context .getType ("fb1" )).isEqualTo (Set .class );
457
+ assertThat (context .getType ("&fb1" )).isEqualTo (GenericHolderFactoryBean .class );
458
+ assertThat (context .getType ("fb1" )).isEqualTo (GenericHolder .class );
439
459
assertThat (context .getBeanNamesForType (FactoryBean .class )).hasSize (2 );
440
- assertThat (context .getBeanNamesForType (SetFactoryBean .class )).hasSize (1 );
460
+ assertThat (context .getBeanNamesForType (GenericHolderFactoryBean .class )).hasSize (1 );
441
461
assertThat (context .getBean ("ip" , FactoryResultInjectionPoint .class ).factoryResult ).isSameAs (context .getBean ("fb1" ));
442
462
}
443
463
@@ -663,16 +683,18 @@ public boolean isSingleton() {
663
683
}
664
684
}
665
685
666
- static class SetFactoryBean implements FactoryBean <Set <String >> {
686
+ static class GenericHolder <T > {}
687
+
688
+ static class GenericHolderFactoryBean implements FactoryBean <GenericHolder <?>> {
667
689
668
690
@ Override
669
- public Set < String > getObject () {
670
- return Collections . emptySet ();
691
+ public GenericHolder <? > getObject () {
692
+ return new GenericHolder <> ();
671
693
}
672
694
673
695
@ Override
674
696
public Class <?> getObjectType () {
675
- return Set .class ;
697
+ return GenericHolder .class ;
676
698
}
677
699
678
700
@ Override
@@ -684,13 +706,13 @@ public boolean isSingleton() {
684
706
static class FactoryResultInjectionPoint {
685
707
686
708
@ Autowired
687
- Set <String > factoryResult ;
709
+ GenericHolder <String > factoryResult ;
688
710
}
689
711
690
712
static class FactoryBeanInjectionPoints extends FactoryResultInjectionPoint {
691
713
692
714
@ Autowired
693
- FactoryBean <Set <String >> factoryBean ;
715
+ FactoryBean <GenericHolder <String >> factoryBean ;
694
716
}
695
717
}
696
718
0 commit comments