title: Can not get locale use LocaleContextHolder.getLocale() in Spring Boot
body: <p>I use Spring boot in my source, and set <code>Locale</code> like bellow:</p>
  
  <pre><code>@Controller
  @RequestMapping(value = "/language")
  public class LocaleController {
  
      @Bean
      public LocaleResolver localeResolver(){
          CookieLocaleResolver localeResolver = new CookieLocaleResolver();
          localeResolver.setDefaultLocale(new Locale("en", "US"));
          return localeResolver;
      }
  
      @RequestMapping(value = "/{lang}", method = RequestMethod.GET)
      public String changeSessionLanguage(HttpServletRequest request, HttpServletResponse response,
              @PathVariable("lang") String lang) {
          LocaleResolver localeResolver = RequestContextUtils.getLocaleResolver(request);
          Locale locale = LocaleContextHolder.getLocale();
          if ("zh".equals(lang)) {
              localeResolver.setLocale(request, response, new Locale("zh", "CN"));
          } else if ("jp".equals(lang)) {
              localeResolver.setLocale(request, response, new Locale("ja", "JP"));
          } else {
              localeResolver.setLocale(request, response, new Locale("en", "US"));
          }
          return "redirect:/";
      }
  }
  </code></pre>
  
  <p>And it works good.</p>
  
  <p>But in Spring security <code>UserDetailsService</code> source, I can't get locale as this:</p>
  
  <pre><code>Locale locale = LocaleContextHolder.getLocale();
  </code></pre>
  
  <p>It always show my browser language no matter I had changed the locale to what.</p>
  
  <p>How can I get the locale correctly?</p>
  
  <p>Thanks!</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I changed code, move <code>LocaleResolver</code> to Configuration class and add <code>RequestContextListener</code> like bellow:</p>
  
  <pre><code>@Configuration
  @WebListener
  public class Config extends RequestContextListener{
  
      @Bean
      public RequestContextListener requestContextListener(){
      return new RequestContextListener();
      }
  
      @Bean
      public LocaleResolver localeResolver(){
      CookieLocaleResolver localeResolver = new CookieLocaleResolver();
      localeResolver.setDefaultLocale(new Locale("en", "US"));
      return localeResolver;
      }
  }
  </code></pre>
  
  <p>But it also can't work.</p>