|
|
|
@ -124,9 +124,14 @@ public class PropertySourceAnnotationTests { |
|
|
|
System.clearProperty("path.to.properties"); |
|
|
|
System.clearProperty("path.to.properties"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@Test(expected = IllegalArgumentException.class) |
|
|
|
* SPR-10820 |
|
|
|
public void withEmptyResourceLocations() { |
|
|
|
*/ |
|
|
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); |
|
|
|
|
|
|
|
ctx.register(ConfigWithEmptyResourceLocations.class); |
|
|
|
|
|
|
|
ctx.refresh(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// SPR-10820
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void orderingWithAndWithoutNameAndMultipleResourceLocations() { |
|
|
|
public void orderingWithAndWithoutNameAndMultipleResourceLocations() { |
|
|
|
// p2 should 'win' as it was registered last
|
|
|
|
// p2 should 'win' as it was registered last
|
|
|
|
@ -136,13 +141,6 @@ public class PropertySourceAnnotationTests { |
|
|
|
assertThat(ctxWithName.getEnvironment().getProperty("testbean.name"), equalTo("p2TestBean")); |
|
|
|
assertThat(ctxWithName.getEnvironment().getProperty("testbean.name"), equalTo("p2TestBean")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test(expected=IllegalArgumentException.class) |
|
|
|
|
|
|
|
public void withEmptyResourceLocations() { |
|
|
|
|
|
|
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); |
|
|
|
|
|
|
|
ctx.register(ConfigWithEmptyResourceLocations.class); |
|
|
|
|
|
|
|
ctx.refresh(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void withNameAndMultipleResourceLocations() { |
|
|
|
public void withNameAndMultipleResourceLocations() { |
|
|
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithNameAndMultipleResourceLocations.class); |
|
|
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithNameAndMultipleResourceLocations.class); |
|
|
|
@ -170,6 +168,15 @@ public class PropertySourceAnnotationTests { |
|
|
|
assertThat(ctx.getEnvironment().getProperty("testbean.name"), equalTo("p2TestBean")); |
|
|
|
assertThat(ctx.getEnvironment().getProperty("testbean.name"), equalTo("p2TestBean")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void withNamedPropertySources() { |
|
|
|
|
|
|
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithNamedPropertySources.class); |
|
|
|
|
|
|
|
assertThat(ctx.getEnvironment().containsProperty("from.p1"), is(true)); |
|
|
|
|
|
|
|
assertThat(ctx.getEnvironment().containsProperty("from.p2"), is(true)); |
|
|
|
|
|
|
|
// p2 should 'win' as it was registered last
|
|
|
|
|
|
|
|
assertThat(ctx.getEnvironment().getProperty("testbean.name"), equalTo("p2TestBean")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void withMissingPropertySource() { |
|
|
|
public void withMissingPropertySource() { |
|
|
|
thrown.expect(BeanDefinitionStoreException.class); |
|
|
|
thrown.expect(BeanDefinitionStoreException.class); |
|
|
|
@ -269,8 +276,8 @@ public class PropertySourceAnnotationTests { |
|
|
|
|
|
|
|
|
|
|
|
@Configuration |
|
|
|
@Configuration |
|
|
|
@PropertySources({ |
|
|
|
@PropertySources({ |
|
|
|
@PropertySource(name = "psName", value="classpath:org/springframework/context/annotation/p1.properties"), |
|
|
|
@PropertySource("classpath:org/springframework/context/annotation/p1.properties"), |
|
|
|
@PropertySource(name = "psName", value="classpath:org/springframework/context/annotation/p2.properties") |
|
|
|
@PropertySource("classpath:org/springframework/context/annotation/p2.properties"), |
|
|
|
}) |
|
|
|
}) |
|
|
|
static class ConfigWithPropertySources { |
|
|
|
static class ConfigWithPropertySources { |
|
|
|
} |
|
|
|
} |
|
|
|
@ -278,9 +285,18 @@ 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/missing.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 { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration |
|
|
|
|
|
|
|
@PropertySources({ |
|
|
|
|
|
|
|
@PropertySource(name = "psName", value = "classpath:org/springframework/context/annotation/p1.properties"), |
|
|
|
|
|
|
|
@PropertySource(name = "psName", value = "classpath:org/springframework/context/annotation/missing.properties"), |
|
|
|
|
|
|
|
@PropertySource(name = "psName", value = "classpath:org/springframework/context/annotation/p2.properties") |
|
|
|
}) |
|
|
|
}) |
|
|
|
static class ConfigWithMissingPropertySource { |
|
|
|
static class ConfigWithMissingPropertySource { |
|
|
|
} |
|
|
|
} |
|
|
|
@ -288,10 +304,10 @@ 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/missing.properties", ignoreResourceNotFound=true), |
|
|
|
@PropertySource(name = "psName", value = "classpath:org/springframework/context/annotation/missing.properties", ignoreResourceNotFound=true), |
|
|
|
@PropertySource(name = "psName", value="classpath:${myPath}/missing.properties", ignoreResourceNotFound=true), |
|
|
|
@PropertySource(name = "psName", value = "classpath:${myPath}/missing.properties", ignoreResourceNotFound=true), |
|
|
|
@PropertySource(name = "psName", value="classpath:org/springframework/context/annotation/p2.properties") |
|
|
|
@PropertySource(name = "psName", value = "classpath:org/springframework/context/annotation/p2.properties") |
|
|
|
}) |
|
|
|
}) |
|
|
|
static class ConfigWithIgnoredPropertySource { |
|
|
|
static class ConfigWithIgnoredPropertySource { |
|
|
|
} |
|
|
|
} |
|
|
|
|