mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
Restored property source ordering (fixing regression from 4.0.x)
Issue: SPR-12198
This commit is contained in:
+1
-2
@@ -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);
|
||||||
|
|||||||
+22
-3
@@ -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")
|
||||||
@@ -367,8 +374,8 @@ public class PropertySourceAnnotationTests {
|
|||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@PropertySources({
|
@PropertySources({
|
||||||
@PropertySource(name = "psName", value = "classpath:org/springframework/context/annotation/p1.properties"),
|
@PropertySource(name = "psName", value = "classpath:org/springframework/context/annotation/p1.properties"),
|
||||||
@PropertySource(name = "psName", value = "classpath:org/springframework/context/annotation/p2.properties"),
|
@PropertySource(name = "psName", value = "classpath:org/springframework/context/annotation/p2.properties"),
|
||||||
})
|
})
|
||||||
static class ConfigWithNamedPropertySources {
|
static class ConfigWithNamedPropertySources {
|
||||||
}
|
}
|
||||||
@@ -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 {
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
testbean.name=p3TestBean
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
testbean.name=p4TestBean
|
||||||
Reference in New Issue
Block a user