Spring provides two out-of-the-box implementations for production:
org.springframework.context.support.ResourceBundleMessageSource : built
on top of the standard java.util.ResourceBundle , sharing its limitations.
org.springframework.context.support.ReloadableResourceBundleMessageSource :
highly configurable, in particular with respect to reloading message definitions.
org.springframework.context.support.ResourceBundleMessageSource , org.springframework.context.support.ReloadableResourceBundleMessageSource
| Modifier and Type | Method and Description |
|---|---|
| public String | Returns: the resolved message if the lookup was successful, otherwise the default message passed as a parameter (which may benull)the message code to look up, e.g. 'calculator.noRateSet'.
MessageSource users are encouraged to base message names on qualified class
or package names, avoiding potential conflicts and ensuring maximum clarity. code, Object[] an array of arguments that will be filled in for params within
the message (params look like "{0}", "{1,date}", "{2,time}" within a message),
or args, String null if nonea default message to return if the lookup fails defaultMessage, Locale the locale in which to do the lookup locale)Try to resolve the message. |
| public String | Returns: the resolved message (nevernull)the message code to look up, e.g. 'calculator.noRateSet'.
MessageSource users are encouraged to base message names on qualified class
or package names, avoiding potential conflicts and ensuring maximum clarity. code, Object[] an array of arguments that will be filled in for params within
the message (params look like "{0}", "{1,date}", "{2,time}" within a message),
or args, Locale null if nonethe locale in which to do the lookup locale)Try to resolve the message. |
| public String | Returns: the resolved message (nevernull since even a
MessageSourceResolvable-provided default message needs to be non-null)the value object storing attributes required to resolve a message
(may include a default message) resolvable, Locale the locale in which to do the lookup locale)Try to resolve the message using all the attributes contained within the
Note We must throw a |
| getMessage | back to summary |
|---|---|
| public String getMessage(String code, Object[] args, String defaultMessage, Locale locale) Try to resolve the message. Return default message if no message was found.
| |
| getMessage | back to summary |
|---|---|
| public String getMessage(String code, Object[] args, Locale locale) throws NoSuchMessageException Try to resolve the message. Treat as an error if the message can't be found.
| |
| getMessage | back to summary |
|---|---|
| public String getMessage(MessageSourceResolvable resolvable, Locale locale) throws NoSuchMessageException Try to resolve the message using all the attributes contained within the
Note We must throw a
| |