Setting up locale switching with Spring MVC

First of all, I must say that I am an absolute newbie to Spring Application development. I am trying to switch the language from 'en' to 'de'. For this I found the config below which I entered into my mvc-dispatcher-servlet.xml

 <bean id="messageSource" class="">
          <property name="basename" value="Messages" />

   <!-- Localization Start -->
   <bean id="localeResolver"
          <property name="defaultLocale" value="en" />

   <bean id="localeChangeInterceptor"
          <property name="paramName" value="language" />

   <bean class="" >
          <property name="interceptors">
                        <ref bean="localeChangeInterceptor" />


After that I expect to be able to change the locale by adding '? language = de 'for the existing URL. So the request http: // localhost: 8080 /? Language = de 'should switch the locale. It didn't work. The website is displayed in a specific language by default

My properties files are in / src / main / resources. Names: "Messages_en.propperties" and "Messages_de.propperties". If I switch the default language to "de", the correct language file is loaded and the website is displayed in German. Does anyone know what is wrong with my configuration?


source to share

1 answer

I believe you need to register LocaleChangeInterceptor with interceptor in Spring

<!-- Declare the Interceptor -->
    <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"
          p:paramName="locale" />


LocaleChangeInterceptor is configured to look up the parameter name 'locale' to indicate a change to the user's locale and is registered as an interceptor using the Spring MVC namespace. For example, adding "locale = es" to the URL will change the locale to Spanish.



All Articles