diff --git a/org.springframework.context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java b/org.springframework.context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java index 3b5d703e52..223fdb65c8 100644 --- a/org.springframework.context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java +++ b/org.springframework.context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java @@ -181,6 +181,9 @@ class ConfigurationClassParser { String name = propertySource.getString("name"); String[] locations = propertySource.getStringArray("value"); int nLocations = locations.length; + if (nLocations == 0) { + throw new IllegalArgumentException("At least one @PropertySource(value) location is required"); + } for (int i = 0; i < nLocations; i++) { locations[0] = this.environment.resolveRequiredPlaceholders(locations[0]); } diff --git a/org.springframework.context/src/test/java/org/springframework/context/annotation/PropertySourceAnnotationTests.java b/org.springframework.context/src/test/java/org/springframework/context/annotation/PropertySourceAnnotationTests.java index 5b487591b7..6649b008ca 100644 --- a/org.springframework.context/src/test/java/org/springframework/context/annotation/PropertySourceAnnotationTests.java +++ b/org.springframework.context/src/test/java/org/springframework/context/annotation/PropertySourceAnnotationTests.java @@ -130,15 +130,11 @@ public class PropertySourceAnnotationTests { assertThat(ctx.getEnvironment().containsProperty("from.p2"), is(true)); } - - @Configuration - @PropertySource( - name = "psName", - value = { - "classpath:org/springframework/context/annotation/p1.properties", - "classpath:org/springframework/context/annotation/p2.properties" - }) - static class ConfigWithNameAndMultipleResourceValues { + @Test(expected=IllegalArgumentException.class) + public void withEmptyResourceLocations() { + AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); + ctx.register(ConfigWithEmptyResourceLocations.class); + ctx.refresh(); } @@ -212,4 +208,10 @@ public class PropertySourceAnnotationTests { }) static class ConfigWithNameAndMultipleResourceLocations { } + + + @Configuration + @PropertySource(value = {}) + static class ConfigWithEmptyResourceLocations { + } }