Restored property source ordering (fixing regression from 4.0.x)

Issue: SPR-12198
This commit is contained in:
Juergen Hoeller 2014-09-18 23:48:35 +02:00
parent f4219ca06b
commit 90b93ffe3f
4 changed files with 25 additions and 5 deletions

View File

@ -375,8 +375,7 @@ class ConfigurationClassParser {
propertySources.addLast(propertySource); propertySources.addLast(propertySource);
} }
else { else {
String firstProcessed = this.propertySourceNames.iterator().next(); propertySources.addFirst(propertySource);
propertySources.addBefore(firstProcessed, propertySource);
} }
} }
this.propertySourceNames.add(name); this.propertySourceNames.add(name);

View File

@ -229,6 +229,13 @@ public class PropertySourceAnnotationTests {
assertThat(ctx.getEnvironment().getProperty("testbean.name"), equalTo("p2TestBean")); assertThat(ctx.getEnvironment().getProperty("testbean.name"), equalTo("p2TestBean"));
} }
@Test
public void orderingWithAndWithoutNameAndFourResourceLocations() {
// SPR-12198: p4 should 'win' as it was registered last
AnnotationConfigApplicationContext ctxWithoutName = new AnnotationConfigApplicationContext(ConfigWithFourResourceLocations.class);
assertThat(ctxWithoutName.getEnvironment().getProperty("testbean.name"), equalTo("p4TestBean"));
}
@Configuration @Configuration
@PropertySource(value="classpath:${unresolvable}/p1.properties") @PropertySource(value="classpath:${unresolvable}/p1.properties")
@ -401,7 +408,7 @@ public class PropertySourceAnnotationTests {
} }
@Import({ ConfigImportedWithSameSourceImportedInDifferentOrder.class }) @Import(ConfigImportedWithSameSourceImportedInDifferentOrder.class)
@PropertySources({ @PropertySources({
@PropertySource("classpath:org/springframework/context/annotation/p1.properties"), @PropertySource("classpath:org/springframework/context/annotation/p1.properties"),
@PropertySource("classpath:org/springframework/context/annotation/p2.properties") @PropertySource("classpath:org/springframework/context/annotation/p2.properties")
@ -420,4 +427,16 @@ public class PropertySourceAnnotationTests {
public static class ConfigImportedWithSameSourceImportedInDifferentOrder { public static class ConfigImportedWithSameSourceImportedInDifferentOrder {
} }
@Configuration
@PropertySource(
value = {
"classpath:org/springframework/context/annotation/p1.properties",
"classpath:org/springframework/context/annotation/p2.properties",
"classpath:org/springframework/context/annotation/p3.properties",
"classpath:org/springframework/context/annotation/p4.properties"
})
static class ConfigWithFourResourceLocations {
}
} }

View File

@ -0,0 +1 @@
testbean.name=p3TestBean

View File

@ -0,0 +1 @@
testbean.name=p4TestBean