@@ -142,16 +142,6 @@ public void withEmptyResourceLocations() {
142
142
ctx .refresh ();
143
143
}
144
144
145
- // SPR-10820
146
- @ Test
147
- public void orderingWithAndWithoutNameAndMultipleResourceLocations () {
148
- // p2 should 'win' as it was registered last
149
- AnnotationConfigApplicationContext ctxWithName = new AnnotationConfigApplicationContext (ConfigWithNameAndMultipleResourceLocations .class );
150
- AnnotationConfigApplicationContext ctxWithoutName = new AnnotationConfigApplicationContext (ConfigWithMultipleResourceLocations .class );
151
- assertThat (ctxWithoutName .getEnvironment ().getProperty ("testbean.name" ), equalTo ("p2TestBean" ));
152
- assertThat (ctxWithName .getEnvironment ().getProperty ("testbean.name" ), equalTo ("p2TestBean" ));
153
- }
154
-
155
145
@ Test
156
146
public void withNameAndMultipleResourceLocations () {
157
147
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext (ConfigWithNameAndMultipleResourceLocations .class );
@@ -202,6 +192,30 @@ public void withIgnoredPropertySource() {
202
192
assertThat (ctx .getEnvironment ().containsProperty ("from.p2" ), is (true ));
203
193
}
204
194
195
+ @ Test
196
+ public void withSameSourceImportedInDifferentOrder () {
197
+ AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext (ConfigWithSameSourceImportedInDifferentOrder .class );
198
+ assertThat (ctx .getEnvironment ().containsProperty ("from.p1" ), is (true ));
199
+ assertThat (ctx .getEnvironment ().containsProperty ("from.p2" ), is (true ));
200
+ assertThat (ctx .getEnvironment ().getProperty ("testbean.name" ), equalTo ("p2TestBean" ));
201
+ }
202
+
203
+ @ Test
204
+ public void orderingWithAndWithoutNameAndMultipleResourceLocations () {
205
+ // SPR-10820: p2 should 'win' as it was registered last
206
+ AnnotationConfigApplicationContext ctxWithName = new AnnotationConfigApplicationContext (ConfigWithNameAndMultipleResourceLocations .class );
207
+ AnnotationConfigApplicationContext ctxWithoutName = new AnnotationConfigApplicationContext (ConfigWithMultipleResourceLocations .class );
208
+ assertThat (ctxWithoutName .getEnvironment ().getProperty ("testbean.name" ), equalTo ("p2TestBean" ));
209
+ assertThat (ctxWithName .getEnvironment ().getProperty ("testbean.name" ), equalTo ("p2TestBean" ));
210
+ }
211
+
212
+ @ Test
213
+ public void orderingWithAndWithoutNameAndFourResourceLocations () {
214
+ // SPR-12198: p4 should 'win' as it was registered last
215
+ AnnotationConfigApplicationContext ctxWithoutName = new AnnotationConfigApplicationContext (ConfigWithFourResourceLocations .class );
216
+ assertThat (ctxWithoutName .getEnvironment ().getProperty ("testbean.name" ), equalTo ("p4TestBean" ));
217
+ }
218
+
205
219
206
220
@ Configuration
207
221
@ PropertySource (value ="classpath:${unresolvable}/p1.properties" )
@@ -326,8 +340,8 @@ static class ConfigWithPropertySources {
326
340
327
341
@ Configuration
328
342
@ PropertySources ({
329
- @ PropertySource (name = "psName" , value = "classpath:org/springframework/context/annotation/p1.properties" ),
330
- @ PropertySource (name = "psName" , value = "classpath:org/springframework/context/annotation/p2.properties" ),
343
+ @ PropertySource (name = "psName" , value = "classpath:org/springframework/context/annotation/p1.properties" ),
344
+ @ PropertySource (name = "psName" , value = "classpath:org/springframework/context/annotation/p2.properties" ),
331
345
})
332
346
static class ConfigWithNamedPropertySources {
333
347
}
@@ -359,4 +373,36 @@ static class ConfigWithIgnoredPropertySource {
359
373
static class ConfigWithEmptyResourceLocations {
360
374
}
361
375
376
+
377
+ @ Import (ConfigImportedWithSameSourceImportedInDifferentOrder .class )
378
+ @ PropertySources ({
379
+ @ PropertySource ("classpath:org/springframework/context/annotation/p1.properties" ),
380
+ @ PropertySource ("classpath:org/springframework/context/annotation/p2.properties" )
381
+ })
382
+ @ Configuration
383
+ public static class ConfigWithSameSourceImportedInDifferentOrder {
384
+
385
+ }
386
+
387
+
388
+ @ Configuration
389
+ @ PropertySources ({
390
+ @ PropertySource ("classpath:org/springframework/context/annotation/p2.properties" ),
391
+ @ PropertySource ("classpath:org/springframework/context/annotation/p1.properties" )
392
+ })
393
+ public static class ConfigImportedWithSameSourceImportedInDifferentOrder {
394
+ }
395
+
396
+
397
+ @ Configuration
398
+ @ PropertySource (
399
+ value = {
400
+ "classpath:org/springframework/context/annotation/p1.properties" ,
401
+ "classpath:org/springframework/context/annotation/p2.properties" ,
402
+ "classpath:org/springframework/context/annotation/p3.properties" ,
403
+ "classpath:org/springframework/context/annotation/p4.properties"
404
+ })
405
+ static class ConfigWithFourResourceLocations {
406
+ }
407
+
362
408
}
0 commit comments