title: Custom Spring Boot starter: how do you contribute i18n messages to the MessageSource?
body: <p>I'm writing a custom Spring Boot starter that other developers will drop into their applications, and this starter contains out-of-the-box controllers and UI screens.</p>
  
  <p>These UI screens are internationalized and the i18n keys/values are in a package file: <code>com/foo/wherever/i18n.properties</code>.</p>
  
  <p>I want to ensure that when my starter is loaded at startup, that these i18n.properties are available in the application's <code>MessageSource</code> automatically so that my UI pages work (rendered via normal Spring Controller + ViewResolver + View implementations) <em>without the app developer having to specify this file themselves</em>.</p>
  
  <p>In other words, they should be able to add my starter to their runtime classpath and everything 'just works' without the need to configure anything.</p>
  
  <p>Now, I have discovered that the app developer can create their own <code>src/main/resources/messages.properties</code> file <em>and</em> manually configure the additional messages file in <code>application.properties</code>:</p>
  
  <pre><code>spring.messages.basename = messages, com.foo.wherever.i18n
  </code></pre>
  
  <p>And this will work.</p>
  
  <p>However, this requires both of the following:</p>
  
  <ol>
  <li>They must manually configure the <code>spring.messages.basename</code> property - it's not automatic. and </li>
  <li>They must have their own <code>messages.properties</code> file in their application classpath.  If a <code>messages.properties</code> file does not exist, <code>spring.messages.basename</code> doesn't even work.  Even if they don't care about i18n, this is still required - not desirable.</li>
  </ol>
  
  <p>I suppose I <em>could</em> move my i18n.properties file to a classpath:/messages.properties file in the starter .jar, but that doesn't seem like a good solution:  if the app dev has their own messages.properties file only one of them would be read, resulting in missing message values.</p>
  
  <p>It seems as if Spring Boot <a href="https://github.com/spring-projects/spring-boot/blob/master/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/MessageSourceAutoConfiguration.java" rel="noreferrer">MessageSourceAutoConfiguration</a> should have a concept of a <code>CompositeMessageSource</code> that iterates over one or more <code>MessageSource</code> instances that are available (and <code>Order</code>ed) in the Spring ApplicationContext and <em>that</em> is used by the DispatcherServlet.  This would allow any starter to contribute to the available messages just by declaring a <code>MessageSource</code> in their auto config</p>
  
  <p>Is it possible to do what I ask? What is the most 'hands off' solution for the app developer?</p>