Configuring a CookieLocaleResolver

We use a CookieLocaleResolver in the following example:

    <bean id="localeResolver"      class="org.springframework.web.servlet.     i18n.CookieLocaleResolver">        <property name="defaultLocale" value="en" />        <property name="cookieName" value="userLocaleCookie"/>        <property name="cookieMaxAge" value="7200"/>     </bean>

Important things to note are as follows:

  • <property name="cookieName" value="userLocaleCookie"/>: The name of the cookie stored in the browser will be userLocaleCookie.
  • <property name="cookieMaxAge" value="7200"/>: The lifetime of the cookie is 2 hours (7200 seconds).
  • Since we are using LocaleChangeInterceptor from the previous example, if you append language=en to any URL, you would be using en locale ...

Get Mastering Spring 5.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.