Skip to content

Commit 7b3bedc

Browse files
committed
Fix detection of dot-based resource bundle basenames
This commit makes sure that properties-based resource bundle location with a dot is detected. It also harmonizes the description of the configuration key as our support is not stricly matching the convention. Closes gh-10092
1 parent 8255835 commit 7b3bedc

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/context/MessageSourceAutoConfiguration.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2017 the original author or authors.
2+
* Copyright 2012-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -59,9 +59,10 @@ public class MessageSourceAutoConfiguration {
5959
private static final Resource[] NO_RESOURCES = {};
6060

6161
/**
62-
* Comma-separated list of basenames, each following the ResourceBundle convention.
63-
* Essentially a fully-qualified classpath location. If it doesn't contain a package
64-
* qualifier (such as "org.mypackage"), it will be resolved from the classpath root.
62+
* Comma-separated list of basenames (essentially a fully-qualified classpath
63+
* location), each following the ResourceBundle convention with relaxed support for
64+
* slash based locations. If it doesn't contain a package qualifier (such as
65+
* "org.mypackage"), it will be resolved from the classpath root.
6566
*/
6667
private String basename = "messages";
6768

@@ -180,9 +181,10 @@ private ConditionOutcome getMatchOutcomeForBasename(ConditionContext context,
180181
}
181182

182183
private Resource[] getResources(ClassLoader classLoader, String name) {
184+
String target = name.replace('.', '/');
183185
try {
184186
return new PathMatchingResourcePatternResolver(classLoader)
185-
.getResources("classpath*:" + name + ".properties");
187+
.getResources("classpath*:" + target + ".properties");
186188
}
187189
catch (Exception ex) {
188190
return NO_RESOURCES;

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/context/MessageSourceAutoConfigurationTests.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2017 the original author or authors.
2+
* Copyright 2012-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -60,8 +60,17 @@ public void testDefaultMessageSource() throws Exception {
6060
}
6161

6262
@Test
63-
public void testMessageSourceCreated() throws Exception {
63+
public void propertiesBundleWithSlashIsDetected() {
6464
load("spring.messages.basename:test/messages");
65+
assertThat(this.context.getBeansOfType(MessageSource.class)).hasSize(1);
66+
assertThat(this.context.getMessage("foo", null, "Foo message", Locale.UK))
67+
.isEqualTo("bar");
68+
}
69+
70+
@Test
71+
public void propertiesBundleWithDotIsDetected() {
72+
load("spring.messages.basename:test.messages");
73+
assertThat(this.context.getBeansOfType(MessageSource.class)).hasSize(1);
6574
assertThat(this.context.getMessage("foo", null, "Foo message", Locale.UK))
6675
.isEqualTo("bar");
6776
}

spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ content into your application; rather pick only the properties that you need.
114114
115115
# INTERNATIONALIZATION ({sc-spring-boot-autoconfigure}/context/MessageSourceAutoConfiguration.{sc-ext}[MessageSourceAutoConfiguration])
116116
spring.messages.always-use-message-format=false # Set whether to always apply the MessageFormat rules, parsing even messages without arguments.
117-
spring.messages.basename=messages # Comma-separated list of basenames, each following the ResourceBundle convention.
117+
spring.messages.basename=messages # Comma-separated list of basenames (essentially a fully-qualified classpath location), each following the ResourceBundle convention with relaxed support for slash based locations.
118118
spring.messages.cache-seconds=-1 # Loaded resource bundle files cache expiration, in seconds. When set to -1, bundles are cached forever.
119119
spring.messages.encoding=UTF-8 # Message bundles encoding.
120120
spring.messages.fallback-to-system-locale=true # Set whether to fall back to the system Locale if no files for a specific Locale have been found.

0 commit comments

Comments
 (0)