Last Modified 2017.10.27


Source :
How to run : Go to root directory and run mvn jetty:run and visit http://localhost:8080.


MessageSource is a component that looks at the locale and determines the message.
ResourceBundleMessageSource and ReloadableResourceBundleMessageSource are implementations.

ResourceBundleMessageSource can only access resources in the classpath.
ReloadableResourceBundleMessageSource can access anywhere the resource is on the file system.

Add the following to spring configuration file.

<bean id="messageSource" class="">
	<property name="basename" value="WEB-INF/classes/messages" />
	<property name="defaultEncoding" value="UTF-8" />

Without <property name="defaultEncoding" value="UTF-8" />, Non english characters are broken.


LocaleResolver is a component that determines the locale.
If you omit LocaleResolver, AcceptHeaderLocaleResolver is selected by default.
AcceptHeaderLocaleResolver uses the locale set in the "accept-language" of the request header.
The operating system's locale is set in the accept-language header.
In this case, the user can not change the locale.
If you want the user to be able to change the locale, you must select SessionLocaleResolver or CookieLocaleResolver as LocaleResolver and you need a LocaleChangeInterceptor.

Add the SessionLocaleResolver and LocalChangeInterceptor settings to the Spring configuration file.

<bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
    <property name="defaultLocale" value="en" />
	<bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
		<property name="paramName" value="lang" />