packagecom.apress.prospringmvc.bookstore.web.config;importorg.springframework.context.support.ReloadableResourceBundleMessageSource;// Other imports omitted@Configuration@EnableWebMvc@ComponentScan(basePackages={"com.apress.prospringmvc.bookstore.web"})publicclassWebMvcContextConfigurationextendsWebMvcConfigurerAdapter{@BeanpublicMessageSourcemessageSource(){ReloadableResourceBundleMessageSourcemessageSource;messageSource=newReloadableResourceBundleMessageSource();messageSource.setBasename("classpath:/messages");messageSource.setUseCodeAsDefaultMessage(true);returnmessageSource;}}
packagecom.apress.prospringmvc.bookstore.web.config;importorg.springframework.context.MessageSource;importorg.springframework.context.support.ReloadableResourceBundleMessageSource;importorg.springframework.web.servlet.HandlerInterceptor;importorg.springframework.web.servlet.LocaleResolver;importorg.springframework.web.servlet.config.annotation.InterceptorRegistry;importorg.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;importorg.springframework.web.servlet.i18n.CookieLocaleResolver;importorg.springframework.web.servlet.i18n.LocaleChangeInterceptor;// Other imports omitted@Configuration@EnableWebMvc@ComponentScan(basePackages={"com.apress.prospringmvc.bookstore.web"})publicclassWebMvcContextConfigurationextendsWebMvcConfigurerAdapter{@OverridepublicvoidaddInterceptors(InterceptorRegistryregistry){registry.addInterceptor(localeChangeInterceptor());}@BeanpublicHandlerInterceptorlocaleChangeInterceptor(){LocaleChangeInterceptorlocaleChangeInterceptor;localeChangeInterceptor=newLocaleChangeInterceptor();localeChangeInterceptor.setParamName("lang");returnlocaleChangeInterceptor;}@BeanpublicLocaleResolverlocaleResolver(){returnnewCookieLocaleResolver();}@BeanpublicMessageSourcemessageSource(){ReloadableResourceBundleMessageSourcemessageSource;messageSource=newReloadableResourceBundleMessageSource();messageSource.setBasename("classpath:/messages");messageSource.setUseCodeAsDefaultMessage(true);returnmessageSource;}}