Browse Source

Allow multiple locations via @PropertySource#value

Issue: SPR-8314
pull/7/head
Chris Beams 14 years ago
parent
commit
2ceeff370a
  1. 12
      org.springframework.context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java
  2. 10
      org.springframework.context/src/main/java/org/springframework/context/annotation/PropertySource.java

12
org.springframework.context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java

@ -174,12 +174,14 @@ class ConfigurationClassParser { @@ -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

10
org.springframework.context/src/main/java/org/springframework/context/annotation/PropertySource.java

@ -117,12 +117,14 @@ public @interface PropertySource { @@ -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();
}

Loading…
Cancel
Save