1.

How are i18n and localization supported in Spring MVC?

Answer»

Spring MVC has LOCALERESOLVER that supports i18n and localization. for supporting both internationalization and localization. The following beans need to be configured in the application:

  • SessionLocaleResolver: This bean plays a vital role to get and resolve the locales from the pre-defined attributes in the user session.

Syntax:

<bean id="localeResolver"class="org.Springframework.web.servlet.i18n.SessionLocaleResolver"&GT; <property name="defaultLocale" value="en" /></bean>
  • LocaleChangeInterceptor: This bean is useful to resolve the parameter from the incoming request.

Syntax:

<bean id="localeChangeInterceptor"class="org.Springframework.web.servlet.i18n.LocaleChangeInterceptor"> <property name="paramName" value="lang" /></bean>
  • DefaultAnnotationHandlerMapping: This REFERS to the HandlerMapping interface implementation which maps the handlers/interceptors BASED on the HTTP paths specified in the @RequestMapping at type or method level.

Syntax:

<bean class="org.Springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"> <property name="interceptors"> <list> <ref bean="localeChangeInterceptor" /> </list> </property></bean>


Discussion

No Comment Found