Allow multiple locations via @PropertySource#value

Issue: SPR-8314

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4364 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
Chris Beams
2011-05-25 10:52:25 +00:00
parent 2a896753d4
commit 5049cd0db3
2 changed files with 13 additions and 9 deletions
@@ -174,12 +174,14 @@ class ConfigurationClassParser {
metadata.getAnnotationAttributes(org.springframework.context.annotation.PropertySource.class.getName());
if (propertySourceAttributes != null) {
String name = (String) propertySourceAttributes.get("name");
String location = (String) propertySourceAttributes.get("value");
String[] locations = (String[]) propertySourceAttributes.get("value");
ClassLoader classLoader = this.resourceLoader.getClassLoader();
ResourcePropertySource ps = StringUtils.hasText(name) ?
new ResourcePropertySource(name, location, classLoader) :
new ResourcePropertySource(location, classLoader);
this.propertySources.push(ps);
for (String location : locations) {
ResourcePropertySource ps = StringUtils.hasText(name) ?
new ResourcePropertySource(name, location, classLoader) :
new ResourcePropertySource(location, classLoader);
this.propertySources.push(ps);
}
}
// process any @ComponentScan annotions
@@ -117,12 +117,14 @@ public @interface PropertySource {
String name() default "";
/**
* Indicate the resource location of the properties file to be loaded.
* Indicate the resource location(s) of the properties file to be loaded.
* For example, {@code "classpath:/com/myco/app.properties"} or
* {@code "file:/path/to/file"}. Note that resource location wildcards
* are not permitted, and that a location must evaluate to exactly one
* {@code .properties} resource.
* are not permitted, and that each location must evaluate to exactly one
* {@code .properties} resource. Each location will be added to the
* enclosing {@code Environment} as its own property source, and in the order
* declared.
*/
String value();
String[] value();
}