Check for existence of ResourceBundle before creating MessageSource

Irritatingly a ResourceBundleMessageSource never gives up trying to
create a resource bundle for every message resolution, so to stop
it logging all those warnings (and probably sucking performance-wise)
we need to disable the MessageSource if a bundle is not provided.

Fixes gh-1019
This commit is contained in:
Dave Syer
2014-06-03 15:53:46 +01:00
parent 1567964e14
commit 0def7644c2
2 changed files with 80 additions and 22 deletions

View File

@@ -46,10 +46,10 @@ public class MessageSourceAutoConfigurationTests {
@Test
public void testMessageSourceCreated() throws Exception {
this.context = new AnnotationConfigApplicationContext();
this.context.register(MessageSourceAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
"spring.messages.basename:test/messages");
this.context.register(MessageSourceAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
this.context.refresh();
assertEquals("bar",
this.context.getMessage("foo", null, "Foo message", Locale.UK));
@@ -58,10 +58,10 @@ public class MessageSourceAutoConfigurationTests {
@Test
public void testMultipleMessageSourceCreated() throws Exception {
this.context = new AnnotationConfigApplicationContext();
this.context.register(MessageSourceAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
"spring.messages.basename:test/messages,test/messages2");
this.context.register(MessageSourceAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
this.context.refresh();
assertEquals("bar",
this.context.getMessage("foo", null, "Foo message", Locale.UK));
@@ -72,10 +72,10 @@ public class MessageSourceAutoConfigurationTests {
@Test
public void testBadEncoding() throws Exception {
this.context = new AnnotationConfigApplicationContext();
this.context.register(MessageSourceAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
"spring.messages.encoding:rubbish");
this.context.register(MessageSourceAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
this.context.refresh();
// Bad encoding just means the messages are ignored
assertEquals("blah", this.context.getMessage("foo", null, "blah", Locale.UK));