- Mastering Spring 5.0
- Ranga Rao Karanam
- 99字
- 2021-07-02 22:12:19
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 for a duration of 2 hours (or until the locale is changed). If you append language=fr to any URL, then you would be using a French locale for 2 hours (or until locale is changed).