title: Get Locale from session object
body: <p>I am noob and want to make internationalization for a spring boot app. This is what I have tried but can not get it to work :</p>
  
  <pre><code>@SpringBootApplication
  public class CarriersApplication extends WebMvcConfigurerAdapter {
  
  @Autowired WebContextHolder webContextHolder;
  
  public static void main(String[] args) {
      SpringApplication.run(CarriersApplication.class, args);
  }
  
  @Bean
  public RestTemplate createRestTemplate() {
      return new RestTemplate();
  }
  
  
  @Bean
  public LocaleResolver localeResolver() {
  
      HttpSession session = webContextHolder.getSession();
      String lang = ((Merchant) session.getAttribute( "principal" )).getLanguage();
  
      // the code above is an attempt to get language from session object to set the 
       // default locale 
      // ex: lang = en,fr
  
      SessionLocaleResolver slr = new SessionLocaleResolver();
      slr.setDefaultLocale( new Locale( lang) );
      return slr;
  
  }
  
  @Bean
  public LocaleChangeInterceptor localeChangeInterceptor() {
      LocaleChangeInterceptor lci = new LocaleChangeInterceptor();
      lci.setParamName("lang");
      return lci;
  }
  
  @Override
  public void addInterceptors(InterceptorRegistry registry) {
      registry.addInterceptor( localeChangeInterceptor());
  }
  
  @Override
  public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
      configurer.enable();
  }
  }
  </code></pre>
  
  <p>My question is: Is there a possibility to get the locale from 'principal' session object in this manner, when I define <code>localeResolver()</code> method?</p>