title: How to I define and get locale-based messages in Spring MVC?
body: <p>I want to define a set of error messages so that when <strong>validation errors generate codes, those codes pick up the corresponding error message</strong> and print them.</p>
  
  <p>For the sake of learning, and to develop an extendable web app, I'd like to follow the proper i18n path, though I only need to define one (english) set of messages now.</p>
  
  <p>So the locales should all default to english when they don't find their own resources (which I'm yet to define).</p>
  
  <p>I've never used any of the i18n functionality of Java. And the spring docs assume that I have this knowledge.</p>
  
  <p>Could someone just give me a gental nudge in the right direction?</p>
  
  <p>I've defined a <code>messageSource</code> in my <code>dispatcher-servlet.xml</code> webapp context. I have a validator which produces a <code>BindingResult</code> object with a rejected field <code>"username"</code>, with code <code>"username.taken"</code>.  I can generate the default message.</p>
  
  <p>Now I just need to get the error message from the <code>errormessages.properties</code> file in my view. </p>
  
  <p><strong>How do I resolve an error code to a message?</strong></p>
  
  <pre><code>&lt;bean id="messageSource"
        class="org.springframework.context.support.ResourceBundleMessageSource"&gt;
    &lt;property name="basenames"&gt;
      &lt;list&gt;
        &lt;value&gt;errormessages&lt;/value&gt;
      &lt;/list&gt;
    &lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>