74
74
import org .springframework .beans .factory .support .ChildBeanDefinition ;
75
75
import org .springframework .beans .factory .support .DefaultListableBeanFactory ;
76
76
import org .springframework .beans .factory .support .ManagedList ;
77
- import org .springframework .beans .factory .support .PropertiesBeanDefinitionReader ;
78
77
import org .springframework .beans .factory .support .RootBeanDefinition ;
79
78
import org .springframework .beans .factory .xml .ConstructorDependenciesBean ;
80
79
import org .springframework .beans .propertyeditors .CustomNumberEditor ;
@@ -139,7 +138,7 @@ void unreferencedSingletonWasInstantiated() {
139
138
Properties p = new Properties ();
140
139
p .setProperty ("x1.(class)" , KnowsIfInstantiated .class .getName ());
141
140
assertThat (!KnowsIfInstantiated .wasInstantiated ()).as ("singleton not instantiated" ).isTrue ();
142
- ( new PropertiesBeanDefinitionReader ( lbf )). registerBeanDefinitions (p );
141
+ registerBeanDefinitions (p );
143
142
lbf .preInstantiateSingletons ();
144
143
assertThat (KnowsIfInstantiated .wasInstantiated ()).as ("singleton was instantiated" ).isTrue ();
145
144
}
@@ -151,7 +150,7 @@ void lazyInitialization() {
151
150
p .setProperty ("x1.(class)" , KnowsIfInstantiated .class .getName ());
152
151
p .setProperty ("x1.(lazy-init)" , "true" );
153
152
assertThat (!KnowsIfInstantiated .wasInstantiated ()).as ("singleton not instantiated" ).isTrue ();
154
- ( new PropertiesBeanDefinitionReader ( lbf )). registerBeanDefinitions (p );
153
+ registerBeanDefinitions (p );
155
154
assertThat (!KnowsIfInstantiated .wasInstantiated ()).as ("singleton not instantiated" ).isTrue ();
156
155
lbf .preInstantiateSingletons ();
157
156
@@ -168,7 +167,7 @@ void factoryBeanDidNotCreatePrototype() {
168
167
DummyFactory .reset ();
169
168
p .setProperty ("x1.singleton" , "false" );
170
169
assertThat (!DummyFactory .wasPrototypeCreated ()).as ("prototype not instantiated" ).isTrue ();
171
- ( new PropertiesBeanDefinitionReader ( lbf )). registerBeanDefinitions (p );
170
+ registerBeanDefinitions (p );
172
171
assertThat (!DummyFactory .wasPrototypeCreated ()).as ("prototype not instantiated" ).isTrue ();
173
172
assertThat (lbf .getType ("x1" )).isEqualTo (TestBean .class );
174
173
lbf .preInstantiateSingletons ();
@@ -189,7 +188,7 @@ void prototypeFactoryBeanIgnoredByNonEagerTypeMatching() {
189
188
DummyFactory .reset ();
190
189
p .setProperty ("x1.(singleton)" , "false" );
191
190
p .setProperty ("x1.singleton" , "false" );
192
- ( new PropertiesBeanDefinitionReader ( lbf )). registerBeanDefinitions (p );
191
+ registerBeanDefinitions (p );
193
192
194
193
assertThat (!DummyFactory .wasPrototypeCreated ()).as ("prototype not instantiated" ).isTrue ();
195
194
String [] beanNames = lbf .getBeanNamesForType (TestBean .class , true , false );
@@ -223,7 +222,7 @@ void singletonFactoryBeanIgnoredByNonEagerTypeMatching() {
223
222
DummyFactory .reset ();
224
223
p .setProperty ("x1.(singleton)" , "false" );
225
224
p .setProperty ("x1.singleton" , "true" );
226
- ( new PropertiesBeanDefinitionReader ( lbf )). registerBeanDefinitions (p );
225
+ registerBeanDefinitions (p );
227
226
228
227
assertThat (!DummyFactory .wasPrototypeCreated ()).as ("prototype not instantiated" ).isTrue ();
229
228
String [] beanNames = lbf .getBeanNamesForType (TestBean .class , true , false );
@@ -256,7 +255,7 @@ void nonInitializedFactoryBeanIgnoredByNonEagerTypeMatching() {
256
255
// Reset static state
257
256
DummyFactory .reset ();
258
257
p .setProperty ("x1.singleton" , "false" );
259
- ( new PropertiesBeanDefinitionReader ( lbf )). registerBeanDefinitions (p );
258
+ registerBeanDefinitions (p );
260
259
261
260
assertThat (!DummyFactory .wasPrototypeCreated ()).as ("prototype not instantiated" ).isTrue ();
262
261
String [] beanNames = lbf .getBeanNamesForType (TestBean .class , true , false );
@@ -289,7 +288,7 @@ void initializedFactoryBeanFoundByNonEagerTypeMatching() {
289
288
// Reset static state
290
289
DummyFactory .reset ();
291
290
p .setProperty ("x1.singleton" , "false" );
292
- ( new PropertiesBeanDefinitionReader ( lbf )). registerBeanDefinitions (p );
291
+ registerBeanDefinitions (p );
293
292
lbf .preInstantiateSingletons ();
294
293
295
294
assertThat (!DummyFactory .wasPrototypeCreated ()).as ("prototype not instantiated" ).isTrue ();
@@ -483,7 +482,7 @@ void empty() {
483
482
@ Test
484
483
void emptyPropertiesPopulation () {
485
484
Properties p = new Properties ();
486
- ( new PropertiesBeanDefinitionReader ( lbf )). registerBeanDefinitions (p );
485
+ registerBeanDefinitions (p );
487
486
assertThat (lbf .getBeanDefinitionCount () == 0 ).as ("No beans defined after ignorable invalid" ).isTrue ();
488
487
}
489
488
@@ -492,7 +491,7 @@ void harmlessIgnorableRubbish() {
492
491
Properties p = new Properties ();
493
492
p .setProperty ("foo" , "bar" );
494
493
p .setProperty ("qwert" , "er" );
495
- ( new PropertiesBeanDefinitionReader ( lbf )). registerBeanDefinitions (p , "test" );
494
+ registerBeanDefinitions (p , "test" );
496
495
assertThat (lbf .getBeanDefinitionCount () == 0 ).as ("No beans defined after harmless ignorable rubbish" ).isTrue ();
497
496
}
498
497
@@ -502,7 +501,7 @@ void propertiesPopulationWithNullPrefix() {
502
501
p .setProperty ("test.(class)" , TestBean .class .getName ());
503
502
p .setProperty ("test.name" , "Tony" );
504
503
p .setProperty ("test.age" , "48" );
505
- int count = ( new PropertiesBeanDefinitionReader ( lbf )). registerBeanDefinitions (p );
504
+ int count = registerBeanDefinitions (p );
506
505
assertThat (count == 1 ).as ("1 beans registered, not " + count ).isTrue ();
507
506
singleTestBean (lbf );
508
507
}
@@ -514,7 +513,7 @@ void propertiesPopulationWithPrefix() {
514
513
p .setProperty (PREFIX + "test.(class)" , TestBean .class .getName ());
515
514
p .setProperty (PREFIX + "test.name" , "Tony" );
516
515
p .setProperty (PREFIX + "test.age" , "0x30" );
517
- int count = ( new PropertiesBeanDefinitionReader ( lbf )). registerBeanDefinitions (p , PREFIX );
516
+ int count = registerBeanDefinitions (p , PREFIX );
518
517
assertThat (count == 1 ).as ("1 beans registered, not " + count ).isTrue ();
519
518
singleTestBean (lbf );
520
519
}
@@ -532,7 +531,7 @@ void simpleReference() {
532
531
p .setProperty (PREFIX + "kerry.age" , "35" );
533
532
p .setProperty (PREFIX + "kerry.spouse(ref)" , "rod" );
534
533
535
- int count = ( new PropertiesBeanDefinitionReader ( lbf )). registerBeanDefinitions (p , PREFIX );
534
+ int count = registerBeanDefinitions (p , PREFIX );
536
535
assertThat (count == 2 ).as ("2 beans registered, not " + count ).isTrue ();
537
536
538
537
TestBean kerry = lbf .getBean ("kerry" , TestBean .class );
@@ -549,7 +548,7 @@ void propertiesWithDotsInKey() {
549
548
p .setProperty ("tb.(class)" , TestBean .class .getName ());
550
549
p .setProperty ("tb.someMap[my.key]" , "my.value" );
551
550
552
- int count = ( new PropertiesBeanDefinitionReader ( lbf )). registerBeanDefinitions (p );
551
+ int count = registerBeanDefinitions (p );
553
552
assertThat (count == 1 ).as ("1 beans registered, not " + count ).isTrue ();
554
553
assertThat (lbf .getBeanDefinitionCount ()).isEqualTo (1 );
555
554
@@ -567,7 +566,7 @@ void unresolvedReference() {
567
566
p .setProperty (PREFIX + "kerry.age" , "35" );
568
567
p .setProperty (PREFIX + "kerry.spouse(ref)" , "rod" );
569
568
570
- new PropertiesBeanDefinitionReader ( lbf ). registerBeanDefinitions (p , PREFIX );
569
+ registerBeanDefinitions (p , PREFIX );
571
570
assertThatExceptionOfType (BeansException .class ).as ("unresolved reference" ).isThrownBy (() ->
572
571
lbf .getBean ("kerry" ));
573
572
}
@@ -690,7 +689,7 @@ void prototype() {
690
689
Properties p = new Properties ();
691
690
p .setProperty ("kerry.(class)" , TestBean .class .getName ());
692
691
p .setProperty ("kerry.age" , "35" );
693
- ( new PropertiesBeanDefinitionReader ( lbf )). registerBeanDefinitions (p );
692
+ registerBeanDefinitions (p );
694
693
TestBean kerry1 = (TestBean ) lbf .getBean ("kerry" );
695
694
TestBean kerry2 = (TestBean ) lbf .getBean ("kerry" );
696
695
assertThat (kerry1 != null ).as ("Non null" ).isTrue ();
@@ -701,7 +700,7 @@ void prototype() {
701
700
p .setProperty ("kerry.(class)" , TestBean .class .getName ());
702
701
p .setProperty ("kerry.(scope)" , "prototype" );
703
702
p .setProperty ("kerry.age" , "35" );
704
- ( new PropertiesBeanDefinitionReader ( lbf )). registerBeanDefinitions (p );
703
+ registerBeanDefinitions (p );
705
704
kerry1 = (TestBean ) lbf .getBean ("kerry" );
706
705
kerry2 = (TestBean ) lbf .getBean ("kerry" );
707
706
assertThat (kerry1 != null ).as ("Non null" ).isTrue ();
@@ -712,7 +711,7 @@ void prototype() {
712
711
p .setProperty ("kerry.(class)" , TestBean .class .getName ());
713
712
p .setProperty ("kerry.(scope)" , "singleton" );
714
713
p .setProperty ("kerry.age" , "35" );
715
- ( new PropertiesBeanDefinitionReader ( lbf )). registerBeanDefinitions (p );
714
+ registerBeanDefinitions (p );
716
715
kerry1 = (TestBean ) lbf .getBean ("kerry" );
717
716
kerry2 = (TestBean ) lbf .getBean ("kerry" );
718
717
assertThat (kerry1 != null ).as ("Non null" ).isTrue ();
@@ -731,7 +730,7 @@ void prototypeCircleLeadsToException() {
731
730
p .setProperty ("rod.age" , "34" );
732
731
p .setProperty ("rod.spouse" , "*kerry" );
733
732
734
- new PropertiesBeanDefinitionReader ( lbf ). registerBeanDefinitions (p );
733
+ registerBeanDefinitions (p );
735
734
assertThatExceptionOfType (BeanCreationException .class ).isThrownBy (() ->
736
735
lbf .getBean ("kerry" ))
737
736
.satisfies (ex -> assertThat (ex .contains (BeanCurrentlyInCreationException .class )).isTrue ());
@@ -745,7 +744,7 @@ void prototypeExtendsPrototype() {
745
744
746
745
p .setProperty ("kerry.(parent)" , "wife" );
747
746
p .setProperty ("kerry.age" , "35" );
748
- ( new PropertiesBeanDefinitionReader ( lbf )). registerBeanDefinitions (p );
747
+ registerBeanDefinitions (p );
749
748
TestBean kerry1 = (TestBean ) lbf .getBean ("kerry" );
750
749
TestBean kerry2 = (TestBean ) lbf .getBean ("kerry" );
751
750
assertThat (kerry1 .getName ()).isEqualTo ("kerry" );
@@ -760,7 +759,7 @@ void prototypeExtendsPrototype() {
760
759
p .setProperty ("kerry.(parent)" , "wife" );
761
760
p .setProperty ("kerry.(singleton)" , "false" );
762
761
p .setProperty ("kerry.age" , "35" );
763
- ( new PropertiesBeanDefinitionReader ( lbf )). registerBeanDefinitions (p );
762
+ registerBeanDefinitions (p );
764
763
assertThat (lbf .isSingleton ("kerry" )).isFalse ();
765
764
kerry1 = (TestBean ) lbf .getBean ("kerry" );
766
765
kerry2 = (TestBean ) lbf .getBean ("kerry" );
@@ -772,7 +771,7 @@ void prototypeExtendsPrototype() {
772
771
p .setProperty ("kerry.(class)" , TestBean .class .getName ());
773
772
p .setProperty ("kerry.(singleton)" , "true" );
774
773
p .setProperty ("kerry.age" , "35" );
775
- ( new PropertiesBeanDefinitionReader ( lbf )). registerBeanDefinitions (p );
774
+ registerBeanDefinitions (p );
776
775
kerry1 = (TestBean ) lbf .getBean ("kerry" );
777
776
kerry2 = (TestBean ) lbf .getBean ("kerry" );
778
777
assertThat (kerry1 != null ).as ("Non null" ).isTrue ();
@@ -823,9 +822,9 @@ void nameAlreadyBound() {
823
822
Properties p = new Properties ();
824
823
p .setProperty ("kerry.(class)" , TestBean .class .getName ());
825
824
p .setProperty ("kerry.age" , "35" );
826
- ( new PropertiesBeanDefinitionReader ( lbf )). registerBeanDefinitions (p );
825
+ registerBeanDefinitions (p );
827
826
try {
828
- ( new PropertiesBeanDefinitionReader ( lbf )). registerBeanDefinitions (p );
827
+ registerBeanDefinitions (p );
829
828
}
830
829
catch (BeanDefinitionStoreException ex ) {
831
830
assertThat (ex .getBeanName ()).isEqualTo ("kerry" );
@@ -965,7 +964,7 @@ void beanReferenceWithNewSyntax() {
965
964
p .setProperty ("k.(class)" , TestBean .class .getName ());
966
965
p .setProperty ("k.name" , "kerry" );
967
966
p .setProperty ("k.spouse" , "*r" );
968
- ( new PropertiesBeanDefinitionReader ( lbf )). registerBeanDefinitions (p );
967
+ registerBeanDefinitions (p );
969
968
TestBean k = (TestBean ) lbf .getBean ("k" );
970
969
TestBean r = (TestBean ) lbf .getBean ("r" );
971
970
assertThat (k .getSpouse () == r ).isTrue ();
@@ -977,7 +976,7 @@ void canEscapeBeanReferenceSyntax() {
977
976
Properties p = new Properties ();
978
977
p .setProperty ("r.(class)" , TestBean .class .getName ());
979
978
p .setProperty ("r.name" , "*" + name );
980
- ( new PropertiesBeanDefinitionReader ( lbf )). registerBeanDefinitions (p );
979
+ registerBeanDefinitions (p );
981
980
TestBean r = (TestBean ) lbf .getBean ("r" );
982
981
assertThat (r .getName ().equals (name )).isTrue ();
983
982
}
@@ -1081,7 +1080,7 @@ void registerExistingSingletonWithReference() {
1081
1080
p .setProperty ("test.name" , "Tony" );
1082
1081
p .setProperty ("test.age" , "48" );
1083
1082
p .setProperty ("test.spouse(ref)" , "singletonObject" );
1084
- ( new PropertiesBeanDefinitionReader ( lbf )). registerBeanDefinitions (p );
1083
+ registerBeanDefinitions (p );
1085
1084
Object singletonObject = new TestBean ();
1086
1085
lbf .registerSingleton ("singletonObject" , singletonObject );
1087
1086
@@ -1117,7 +1116,7 @@ void registerExistingSingletonWithNameOverriding() {
1117
1116
p .setProperty ("test.name" , "Tony" );
1118
1117
p .setProperty ("test.age" , "48" );
1119
1118
p .setProperty ("test.spouse(ref)" , "singletonObject" );
1120
- ( new PropertiesBeanDefinitionReader ( lbf )). registerBeanDefinitions (p );
1119
+ registerBeanDefinitions (p );
1121
1120
lbf .registerBeanDefinition ("singletonObject" , new RootBeanDefinition (PropertiesFactoryBean .class ));
1122
1121
Object singletonObject = new TestBean ();
1123
1122
lbf .registerSingleton ("singletonObject" , singletonObject );
@@ -2895,6 +2894,16 @@ void registrationOfManySingletonsIsFastEnough() {
2895
2894
}
2896
2895
}
2897
2896
2897
+ @ SuppressWarnings ("deprecation" )
2898
+ private int registerBeanDefinitions (Properties p ) {
2899
+ return (new org .springframework .beans .factory .support .PropertiesBeanDefinitionReader (lbf )).registerBeanDefinitions (p );
2900
+ }
2901
+
2902
+ @ SuppressWarnings ("deprecation" )
2903
+ private int registerBeanDefinitions (Properties p , String prefix ) {
2904
+ return (new org .springframework .beans .factory .support .PropertiesBeanDefinitionReader (lbf )).registerBeanDefinitions (p , prefix );
2905
+ }
2906
+
2898
2907
2899
2908
static class A { }
2900
2909
0 commit comments