Merge branch '1.5.x'

pull/11587/head
Stephane Nicoll 7 years ago
commit df647605af

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -118,9 +118,10 @@ public class MessageSourceAutoConfiguration {
} }
private Resource[] getResources(ClassLoader classLoader, String name) { private Resource[] getResources(ClassLoader classLoader, String name) {
String target = name.replace('.', '/');
try { try {
return new PathMatchingResourcePatternResolver(classLoader) return new PathMatchingResourcePatternResolver(classLoader)
.getResources("classpath*:" + name + ".properties"); .getResources("classpath*:" + target + ".properties");
} }
catch (Exception ex) { catch (Exception ex) {
return NO_RESOURCES; return NO_RESOURCES;

@ -30,9 +30,10 @@ import java.time.Duration;
public class MessageSourceProperties { public class MessageSourceProperties {
/** /**
* Comma-separated list of basenames, each following the ResourceBundle convention. * Comma-separated list of basenames (essentially a fully-qualified classpath
* Essentially a fully-qualified classpath location. If it doesn't contain a package * location), each following the ResourceBundle convention with relaxed support for
* qualifier (such as "org.mypackage"), it will be resolved from the classpath root. * slash based locations. If it doesn't contain a package qualifier (such as
* "org.mypackage"), it will be resolved from the classpath root.
*/ */
private String basename = "messages"; private String basename = "messages";

@ -55,11 +55,24 @@ public class MessageSourceAutoConfigurationTests {
} }
@Test @Test
public void testMessageSourceCreated() { public void propertiesBundleWithSlashIsDetected() {
this.contextRunner.withPropertyValues("spring.messages.basename:test/messages") this.contextRunner.withPropertyValues("spring.messages.basename:test/messages")
.run((context) -> assertThat( .run((context) -> {
context.getMessage("foo", null, "Foo message", Locale.UK)) assertThat(context).hasSingleBean(MessageSource.class); assertThat(
.isEqualTo("bar")); context.getMessage("foo", null, "Foo message", Locale.UK))
.isEqualTo("bar");
});
}
@Test
public void propertiesBundleWithDotIsDetected() {
this.contextRunner.withPropertyValues("spring.messages.basename:test.messages")
.run((context) -> {
assertThat(context).hasSingleBean(MessageSource.class);
assertThat(
context.getMessage("foo", null, "Foo message", Locale.UK))
.isEqualTo("bar");
});
} }
@Test @Test

@ -121,7 +121,7 @@ content into your application. Rather, pick only the properties that you need.
# INTERNATIONALIZATION ({sc-spring-boot-autoconfigure}/context/MessageSourceProperties.{sc-ext}[MessageSourceProperties]) # INTERNATIONALIZATION ({sc-spring-boot-autoconfigure}/context/MessageSourceProperties.{sc-ext}[MessageSourceProperties])
spring.messages.always-use-message-format=false # Whether to always apply the MessageFormat rules, parsing even messages without arguments. spring.messages.always-use-message-format=false # Whether to always apply the MessageFormat rules, parsing even messages without arguments.
spring.messages.basename=messages # Comma-separated list of basenames, each following the ResourceBundle convention. 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.
spring.messages.cache-duration=-1 # Loaded resource bundle files cache duration. When not set, bundles are cached forever. spring.messages.cache-duration=-1 # Loaded resource bundle files cache duration. When not set, bundles are cached forever.
spring.messages.encoding=UTF-8 # Message bundles encoding. spring.messages.encoding=UTF-8 # Message bundles encoding.
spring.messages.fallback-to-system-locale=true # Whether to fall back to the system Locale if no files for a specific Locale have been found. spring.messages.fallback-to-system-locale=true # Whether to fall back to the system Locale if no files for a specific Locale have been found.

Loading…
Cancel
Save