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 ;
@@ -794,6 +797,12 @@ public void testNameClashBetweenConfigurationClassAndBean() {
794
797
ctx .getBean ("myTestBean" , TestBean .class );
795
798
}
796
799
800
+ @ Test
801
+ public void testBeanDefinitionRegistryPostProcessorConfig () {
802
+ ApplicationContext ctx = new AnnotationConfigApplicationContext (BeanDefinitionRegistryPostProcessorConfig .class );
803
+ assertTrue (ctx .getBean ("myTestBean" ) instanceof TestBean );
804
+ }
805
+
797
806
798
807
// -------------------------------------------------------------------------
799
808
@@ -860,17 +869,15 @@ public Bar(Foo foo) {
860
869
@ Configuration
861
870
static class UnloadedConfig {
862
871
863
- public @ Bean
864
- Foo foo () {
872
+ public @ Bean Foo foo () {
865
873
return new Foo ();
866
874
}
867
875
}
868
876
869
877
@ Configuration
870
878
static class LoadedConfig {
871
879
872
- public @ Bean
873
- Bar bar () {
880
+ public @ Bean Bar bar () {
874
881
return new Bar (new Foo ());
875
882
}
876
883
}
@@ -884,9 +891,7 @@ public static class ScopedProxyConsumer {
884
891
@ Configuration
885
892
public static class ScopedProxyConfigurationClass {
886
893
887
- @ Bean
888
- @ Lazy
889
- @ Scope (proxyMode = ScopedProxyMode .INTERFACES )
894
+ @ Bean @ Lazy @ Scope (proxyMode = ScopedProxyMode .INTERFACES )
890
895
public ITestBean scopedClass () {
891
896
return new TestBean ();
892
897
}
@@ -1475,4 +1480,21 @@ public TestBean thing() {
1475
1480
public abstract TestBean getTestBean ();
1476
1481
}
1477
1482
1483
+ @ Configuration
1484
+ static class BeanDefinitionRegistryPostProcessorConfig {
1485
+
1486
+ @ Bean
1487
+ public static BeanDefinitionRegistryPostProcessor bdrpp () {
1488
+ return new BeanDefinitionRegistryPostProcessor () {
1489
+ @ Override
1490
+ public void postProcessBeanDefinitionRegistry (BeanDefinitionRegistry registry ) {
1491
+ registry .registerBeanDefinition ("myTestBean" , new RootBeanDefinition (TestBean .class ));
1492
+ }
1493
+ @ Override
1494
+ public void postProcessBeanFactory (ConfigurableListableBeanFactory beanFactory ) {
1495
+ }
1496
+ };
1497
+ }
1498
+ }
1499
+
1478
1500
}
0 commit comments