5
votes

I am converting spring MVC to spring boot (2.0.3.RELEASE) project.

I am using this in spring boot, it works:

@Bean
public MessageSource messageSource() {
    ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
    messageSource.setBasenames("classpath:/locale/normal/message", "classpath:/locale/validation/message");
    messageSource.setDefaultEncoding("UTF-8");
    return messageSource;
}

I try to use spring boot auto-configuration (via application.properties) as below (remove the manual bean configuration above):

spring.messages.basename=classpath:/locale/normal/message,classpath:/locale/validation/message

I tried below, it doesn't work too:

spring.messages.basename=/locale/normal/message,/locale/validation/message

I read their documentation below:

# INTERNATIONALIZATION (MessageSourceProperties)
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 (essentially a fully-qualified classpath location), each following the ResourceBundle convention with relaxed support for slash based locations.
spring.messages.cache-duration= # Loaded resource bundle files cache duration. When not set, bundles are cached forever. If a duration suffix is not specified, seconds will be used.
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.use-code-as-default-message=false # Whether to use the message code as the default message instead of throwing a "NoSuchMessageException". Recommended during development only.

I put the message properties file in the classpath:

src\main\resources\locale\normal
src\main\resources\locale\validation

I try a lot of combination, but it doesn't work, why?

The error I encounter :

javax.servlet.jsp.JspTagException: No message found under code 'login.timeout' for locale 'en'.

(I am pretty sure the message code is in my properties file for all locale.)

I am using Spring tag to load the localized message:

<spring:message code="${param.error}" />
1
Which version are you using? - M. Deinum
forgot to mention, it is 2.0.3.RELEASE - Sam YC
Also what doesn't work exactly? - M. Deinum
Can you please give the exception or error you are getting - Dinesh
updated the error message that I encountered. - Sam YC

1 Answers

0
votes

try use # instead $ - <spring:message code="#{param.error}" />