From 391dd90e8418d953990737b527256faeb15e2f37 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 16 Mar 2026 12:23:35 +0100 Subject: [PATCH] Support "classpath*:" prefix for resource bundle basename Closes gh-36292 See gh-36415 --- .../ReloadableResourceBundleMessageSource.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/spring-context/src/main/java/org/springframework/context/support/ReloadableResourceBundleMessageSource.java b/spring-context/src/main/java/org/springframework/context/support/ReloadableResourceBundleMessageSource.java index 851aeed9da9..305852097cc 100644 --- a/spring-context/src/main/java/org/springframework/context/support/ReloadableResourceBundleMessageSource.java +++ b/spring-context/src/main/java/org/springframework/context/support/ReloadableResourceBundleMessageSource.java @@ -60,9 +60,13 @@ import org.springframework.util.StringUtils; * are treated in a slightly different fashion than the "basenames" property of * {@link ResourceBundleMessageSource}. It follows the basic ResourceBundle rule of not * specifying file extension or language codes, but can refer to any Spring resource - * location (instead of being restricted to classpath resources). With a "classpath:" - * prefix, resources can still be loaded from the classpath, but "cacheSeconds" values - * other than "-1" (caching forever) might not work reliably in this case. + * location (instead of being restricted to classpath resources). + * + *

With a "classpath:" prefix, resources can still be loaded from the classpath, + * but "cacheSeconds" values other than "-1" (caching forever) are not expected to + * be effective in this case. As of 7.1, a "classpath*:" prefix is accepted as well, + * loading all classpath resources of the same fully-qualified name: for example, + * "classpath*:/messages.properties" or "classpath*:META-INF/messages.properties". * *

For a typical web application, message files could be placed in {@code WEB-INF}: * for example, a "WEB-INF/messages" basename would find a "WEB-INF/messages.properties", @@ -562,8 +566,8 @@ public class ReloadableResourceBundleMessageSource extends AbstractResourceBased */ protected Properties loadProperties(Resource resource, String filename) throws IOException { Properties props = newProperties(); - try (InputStream inputStream = resource.getInputStream()) { - String resourceFilename = resource.getFilename(); + String resourceFilename = resource.getFilename(); + resource.consumeContent(inputStream -> { if (resourceFilename != null && resourceFilename.endsWith(XML_EXTENSION)) { if (logger.isDebugEnabled()) { logger.debug("Loading properties [" + resource.getFilename() + "]"); @@ -594,8 +598,8 @@ public class ReloadableResourceBundleMessageSource extends AbstractResourceBased this.propertiesPersister.load(props, inputStream); } } - return props; - } + }); + return props; } /**