Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
7be2d97d
Commit
7be2d97d
authored
Mar 19, 2014
by
Chris Savory
Committed by
Dave Syer
Mar 20, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow multiple MessageSources that are comma separated.
Fixes gh-532, Fixes gh-506
parent
632af6b1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
5 deletions
+26
-5
MessageSourceAutoConfiguration.java
...rk/boot/autoconfigure/MessageSourceAutoConfiguration.java
+8
-2
MessageSourceAutoConfigurationTests.java
...ot/autoconfigure/MessageSourceAutoConfigurationTests.java
+17
-3
messages2.properties
...utoconfigure/src/test/resources/test/messages2.properties
+1
-0
No files found.
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/MessageSourceAutoConfiguration.java
View file @
7be2d97d
...
...
@@ -16,6 +16,9 @@
package
org
.
springframework
.
boot
.
autoconfigure
;
import
static
org
.
springframework
.
util
.
StringUtils
.
commaDelimitedListToStringArray
;
import
static
org
.
springframework
.
util
.
StringUtils
.
trimAllWhitespace
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.bind.RelaxedPropertyResolver
;
import
org.springframework.context.EnvironmentAware
;
...
...
@@ -26,10 +29,11 @@ import org.springframework.context.support.ResourceBundleMessageSource;
import
org.springframework.core.Ordered
;
import
org.springframework.core.annotation.Order
;
import
org.springframework.core.env.Environment
;
import
org.springframework.util.StringUtils
;
/**
* {@link EnableAutoConfiguration Auto-configuration} for {@link MessageSource}.
*
*
* @author Dave Syer
*/
@Configuration
...
...
@@ -48,7 +52,9 @@ public class MessageSourceAutoConfiguration implements EnvironmentAware {
public
MessageSource
messageSource
()
{
ResourceBundleMessageSource
messageSource
=
new
ResourceBundleMessageSource
();
String
basename
=
this
.
environment
.
getProperty
(
"basename"
,
"messages"
);
messageSource
.
setBasename
(
basename
);
if
(
StringUtils
.
hasText
(
basename
))
{
messageSource
.
setBasenames
(
commaDelimitedListToStringArray
(
trimAllWhitespace
(
basename
)));
}
String
encoding
=
this
.
environment
.
getProperty
(
"encoding"
,
"utf-8"
);
messageSource
.
setDefaultEncoding
(
encoding
);
return
messageSource
;
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/MessageSourceAutoConfigurationTests.java
View file @
7be2d97d
...
...
@@ -16,17 +16,17 @@
package
org
.
springframework
.
boot
.
autoconfigure
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
java.util.Locale
;
import
org.junit.Test
;
import
org.springframework.boot.test.EnvironmentTestUtils
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
/**
* Tests for {@link MessageSourceAutoConfiguration}.
*
*
* @author Dave Syer
*/
public
class
MessageSourceAutoConfigurationTests
{
...
...
@@ -55,6 +55,20 @@ public class MessageSourceAutoConfigurationTests {
this
.
context
.
getMessage
(
"foo"
,
null
,
"Foo message"
,
Locale
.
UK
));
}
@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
.
refresh
();
assertEquals
(
"bar"
,
this
.
context
.
getMessage
(
"foo"
,
null
,
"Foo message"
,
Locale
.
UK
));
assertEquals
(
"bar-bar"
,
this
.
context
.
getMessage
(
"foo-foo"
,
null
,
"Foo-Foo message"
,
Locale
.
UK
));
}
@Test
public
void
testBadEncoding
()
throws
Exception
{
this
.
context
=
new
AnnotationConfigApplicationContext
();
...
...
spring-boot-autoconfigure/src/test/resources/test/messages2.properties
0 → 100644
View file @
7be2d97d
foo-foo
=
bar-bar
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment