From 2ceeff370aff402bd669f9125d93e99d09e8ce71 Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Wed, 25 May 2011 10:52:25 +0000 Subject: [PATCH] Allow multiple locations via @PropertySource#value Issue: SPR-8314 --- .../context/annotation/ConfigurationClassParser.java | 12 +++++++----- .../context/annotation/PropertySource.java | 10 ++++++---- 2 files changed, 13 insertions(+), 9 deletions(-) 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 e00c6b2485..13a7b82487 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 @@ -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 diff --git a/org.springframework.context/src/main/java/org/springframework/context/annotation/PropertySource.java b/org.springframework.context/src/main/java/org/springframework/context/annotation/PropertySource.java index 4cb749d766..ead2968c89 100644 --- a/org.springframework.context/src/main/java/org/springframework/context/annotation/PropertySource.java +++ b/org.springframework.context/src/main/java/org/springframework/context/annotation/PropertySource.java @@ -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(); }