diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/MessageSourceAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/MessageSourceAutoConfiguration.java index 2e8dc697aee..2aa72899af5 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/MessageSourceAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/MessageSourceAutoConfiguration.java @@ -16,9 +16,7 @@ package org.springframework.boot.autoconfigure; -import java.util.Locale; -import java.util.MissingResourceException; -import java.util.ResourceBundle; +import java.io.IOException; import org.springframework.boot.autoconfigure.MessageSourceAutoConfiguration.ResourceBundleCondition; import org.springframework.boot.autoconfigure.condition.ConditionOutcome; @@ -34,6 +32,8 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.support.ResourceBundleMessageSource; import org.springframework.core.Ordered; import org.springframework.core.annotation.Order; +import org.springframework.core.io.Resource; +import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import org.springframework.core.type.AnnotatedTypeMetadata; import org.springframework.util.StringUtils; @@ -102,23 +102,28 @@ public class MessageSourceAutoConfiguration { AnnotatedTypeMetadata metadata) { String basename = context.getEnvironment().getProperty( "spring.messages.basename", "messages"); - if (!StringUtils.hasText(basename)) { - return ConditionOutcome.noMatch("Empty spring.messages.basename"); - } for (String name : commaDelimitedListToStringArray(trimAllWhitespace(basename))) { + Resource[] resources; try { - ResourceBundle.getBundle(name, Locale.getDefault(), - context.getClassLoader()); + resources = new PathMatchingResourcePatternResolver( + context.getClassLoader()).getResources("classpath*:" + name + + "*.properties"); + } + catch (IOException e) { + continue; } - catch (MissingResourceException e) { - return ConditionOutcome - .noMatch("Bundle found for spring.messages.basename: " + name); + for (Resource resource : resources) { + + if (resource.exists()) { + return ConditionOutcome + .match("Bundle found for spring.messages.basename: " + + name); + } } } - return ConditionOutcome.match("Bundle found for spring.messages.basename: " - + basename); + return ConditionOutcome + .noMatch("No bundle found for spring.messages.basename: " + basename); } - } } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/MessageSourceAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/MessageSourceAutoConfigurationTests.java index 5c68638befe..c1f2a38a4a4 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/MessageSourceAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/MessageSourceAutoConfigurationTests.java @@ -58,6 +58,18 @@ public class MessageSourceAutoConfigurationTests { this.context.getMessage("foo", null, "Foo message", Locale.UK)); } + @Test + public void testEncodingWorks() throws Exception { + this.context = new AnnotationConfigApplicationContext(); + EnvironmentTestUtils.addEnvironment(this.context, + "spring.messages.basename:test/swedish"); + this.context.register(MessageSourceAutoConfiguration.class, + PropertyPlaceholderAutoConfiguration.class); + this.context.refresh(); + assertEquals("Some text with some swedish öäå!", + this.context.getMessage("foo", null, "Foo message", Locale.UK)); + } + @Test public void testMultipleMessageSourceCreated() throws Exception { this.context = new AnnotationConfigApplicationContext(); diff --git a/spring-boot-autoconfigure/src/test/resources/test/swedish.properties b/spring-boot-autoconfigure/src/test/resources/test/swedish.properties new file mode 100644 index 00000000000..9a876aade96 --- /dev/null +++ b/spring-boot-autoconfigure/src/test/resources/test/swedish.properties @@ -0,0 +1 @@ +foo=Some text with some swedish öäå!