Rework @PropertySource early parsing logic

Rework the @PropertySource parsing logic recently changed in commit
7c608886 to deal with the same source appearing on a @Configuration
class and an @Import class.

Processing now occurs in a single sweep, with any previously added
sources being converted to a CompositePropertySource.

Issue: SPR-12115
This commit is contained in:
Phillip Webb
2014-08-21 21:21:15 -07:00
parent b73c531527
commit 84564a0c7b
5 changed files with 177 additions and 86 deletions

View File

@@ -210,6 +210,14 @@ public class PropertySourceAnnotationTests {
assertThat(ctx.getEnvironment().containsProperty("from.p2"), is(true));
}
@Test
public void withSameSourceImportedInDifferentOrder() throws Exception {
AnnotationConfigApplicationContext ctx =new AnnotationConfigApplicationContext(ConfigWithSameSourceImportedInDifferentOrder.class);
assertThat(ctx.getEnvironment().containsProperty("from.p1"), is(true));
assertThat(ctx.getEnvironment().containsProperty("from.p2"), is(true));
assertThat(ctx.getEnvironment().getProperty("testbean.name"), equalTo("p2TestBean"));
}
@Configuration
@PropertySource(value="classpath:${unresolvable}/p1.properties")
@@ -354,4 +362,22 @@ public class PropertySourceAnnotationTests {
static class ConfigWithEmptyResourceLocations {
}
@Import({ ConfigImportedWithSameSourceImportedInDifferentOrder.class })
@PropertySources({
@PropertySource("classpath:org/springframework/context/annotation/p1.properties"),
@PropertySource("classpath:org/springframework/context/annotation/p2.properties")
})
@Configuration
public static class ConfigWithSameSourceImportedInDifferentOrder {
}
@Configuration
@PropertySources({
@PropertySource("classpath:org/springframework/context/annotation/p2.properties"),
@PropertySource("classpath:org/springframework/context/annotation/p1.properties")
})
public static class ConfigImportedWithSameSourceImportedInDifferentOrder {
}
}