title: How to change messagesource with locale in spring boot?
body: <p>I got problem with muitle messeage resources in spring boot like this:</p>
  
  <p>this is my application.yml:</p>
  
  <pre><code>...
  spring:
     messages:
        basename: i18n/messages_fr,i18n/messages_en
  </code></pre>
  
  <p>this is my test class:</p>
  
  <pre><code>public class MessageSourceTest {
  @Autowired
  MessageSource messageSource;
  
  public String getMessage(String key, String keyLang) {
      Locale locale = Locale.forLanguageTag(keyLang); // keyLang = "en", or "fr"
      String message = messageSource.getMessage(key, null, locale);
      return message;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Problem is that I always get message from i18n/messages_fr no matter what I set locale is "en" or "fr".</p>
  
  <p>If I set application.yml to:</p>
  
  <pre><code>basename: i18n/messages_en,i18n/messages_fr
  </code></pre>
  
  <p>then I got message from i18n/messages_en</p>
  
  <p>So, is there any way that i can get messages with dynamically locale.</p>
  
  <p>(Just in backend, not set throught client with localeResolver and addInterceptors, something like this: <a href="http://www.baeldung.com/spring-boot-internationalization" rel="nofollow noreferrer">http://www.baeldung.com/spring-boot-internationalization</a>)</p>