43
43
import org .springframework .beans .factory .annotation .Qualifier ;
44
44
import org .springframework .beans .factory .annotation .QualifierAnnotationAutowireCandidateResolver ;
45
45
import org .springframework .beans .factory .config .BeanDefinitionHolder ;
46
+ import org .springframework .beans .factory .config .ConfigurableListableBeanFactory ;
47
+ import org .springframework .beans .factory .support .BeanDefinitionRegistry ;
48
+ import org .springframework .beans .factory .support .BeanDefinitionRegistryPostProcessor ;
46
49
import org .springframework .beans .factory .support .ChildBeanDefinition ;
47
50
import org .springframework .beans .factory .support .DefaultListableBeanFactory ;
48
51
import org .springframework .beans .factory .support .RootBeanDefinition ;
@@ -806,6 +809,12 @@ public void testNameClashBetweenConfigurationClassAndBean() {
806
809
ctx .getBean ("myTestBean" , TestBean .class );
807
810
}
808
811
812
+ @ Test
813
+ public void testBeanDefinitionRegistryPostProcessorConfig () {
814
+ ApplicationContext ctx = new AnnotationConfigApplicationContext (BeanDefinitionRegistryPostProcessorConfig .class );
815
+ assertTrue (ctx .getBean ("myTestBean" ) instanceof TestBean );
816
+ }
817
+
809
818
810
819
// -------------------------------------------------------------------------
811
820
@@ -902,17 +911,15 @@ public Bar(Foo foo) {
902
911
@ Configuration
903
912
static class UnloadedConfig {
904
913
905
- public @ Bean
906
- Foo foo () {
914
+ public @ Bean Foo foo () {
907
915
return new Foo ();
908
916
}
909
917
}
910
918
911
919
@ Configuration
912
920
static class LoadedConfig {
913
921
914
- public @ Bean
915
- Bar bar () {
922
+ public @ Bean Bar bar () {
916
923
return new Bar (new Foo ());
917
924
}
918
925
}
@@ -926,9 +933,7 @@ public static class ScopedProxyConsumer {
926
933
@ Configuration
927
934
public static class ScopedProxyConfigurationClass {
928
935
929
- @ Bean
930
- @ Lazy
931
- @ Scope (proxyMode = ScopedProxyMode .INTERFACES )
936
+ @ Bean @ Lazy @ Scope (proxyMode = ScopedProxyMode .INTERFACES )
932
937
public ITestBean scopedClass () {
933
938
return new TestBean ();
934
939
}
@@ -1517,4 +1522,21 @@ public TestBean thing() {
1517
1522
public abstract TestBean getTestBean ();
1518
1523
}
1519
1524
1525
+ @ Configuration
1526
+ static class BeanDefinitionRegistryPostProcessorConfig {
1527
+
1528
+ @ Bean
1529
+ public static BeanDefinitionRegistryPostProcessor bdrpp () {
1530
+ return new BeanDefinitionRegistryPostProcessor () {
1531
+ @ Override
1532
+ public void postProcessBeanDefinitionRegistry (BeanDefinitionRegistry registry ) {
1533
+ registry .registerBeanDefinition ("myTestBean" , new RootBeanDefinition (TestBean .class ));
1534
+ }
1535
+ @ Override
1536
+ public void postProcessBeanFactory (ConfigurableListableBeanFactory beanFactory ) {
1537
+ }
1538
+ };
1539
+ }
1540
+ }
1541
+
1520
1542
}
0 commit comments