Support for resource patterns in @PropertySource locations

Closes gh-21325
This commit is contained in:
Juergen Hoeller
2023-08-14 19:16:52 +02:00
parent 3228502108
commit 9c74c25961
2 changed files with 25 additions and 9 deletions

View File

@@ -46,6 +46,7 @@ import org.springframework.util.ReflectionUtils;
*
* @author Stephane Nicoll
* @author Sam Brannen
* @author Juergen Hoeller
* @since 6.0
* @see PropertySourceDescriptor
*/
@@ -58,14 +59,14 @@ public class PropertySourceProcessor {
private final ConfigurableEnvironment environment;
private final ResourceLoader resourceLoader;
private final ResourcePatternResolver resourcePatternResolver;
private final List<String> propertySourceNames = new ArrayList<>();
public PropertySourceProcessor(ConfigurableEnvironment environment, ResourceLoader resourceLoader) {
this.environment = environment;
this.resourceLoader = resourceLoader;
this.resourcePatternResolver = ResourcePatternUtils.getResourcePatternResolver(resourceLoader);
}
@@ -87,8 +88,9 @@ public class PropertySourceProcessor {
for (String location : locations) {
try {
String resolvedLocation = this.environment.resolveRequiredPlaceholders(location);
Resource resource = this.resourceLoader.getResource(resolvedLocation);
addPropertySource(factory.createPropertySource(name, new EncodedResource(resource, encoding)));
for (Resource resource : this.resourcePatternResolver.getResources(resolvedLocation)) {
addPropertySource(factory.createPropertySource(name, new EncodedResource(resource, encoding)));
}
}
catch (RuntimeException | IOException ex) {
// Placeholders not resolvable (IllegalArgumentException) or resource not found when trying to open it