title: Defining MessageSource and LocaleResolver beans in Spring MVC for adding i18n support
body: <p>I'm trying to add i18n support to a Spring MVC project(3.2.0.RELEASE). I have two bundles below /src/main/resources/bundle:</p>
  
  <pre><code>messageBundle_en.properties
  messageBundle_vi.properties
  </code></pre>
  
  <p>And the configurations for spring mvc as below:</p>
  
  <pre><code>&lt;bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
      &lt;property name="cache" value="false" /&gt;
      &lt;property name="prefix" value="/WEB-INF/jsp/" /&gt;
      &lt;property name="suffix" value=".jsp" /&gt;
  &lt;/bean&gt;
  
  &lt;bean class="org.springframework.context.support.ReloadableResourceBundleMessageSource"&gt;
      &lt;property name="basename" value="classpath:bundle/messageBundle" /&gt;
  &lt;/bean&gt;
  &lt;bean class="org.springframework.web.servlet.i18n.CookieLocaleResolver"&gt;
      &lt;property name="defaultLocale" value="vi" /&gt;
  &lt;/bean&gt;
  &lt;mvc:interceptors&gt;
      &lt;bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"&gt;
          &lt;property name="paramName" value="lang" /&gt;
      &lt;/bean&gt;
  &lt;/mvc:interceptors&gt;
  </code></pre>
  
  <p>with above configurations the application is not working. The error was</p>
  
  <pre><code>org.apache.jasper.JasperException: javax.servlet.ServletException: javax.servlet.jsp.JspTagException: No message found under code 'message.home.header.welcome' for locale 'en_US'.
      org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:549)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
      org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
  </code></pre>
  
  <p>I spent many hours comparing with tutorials of adding i18n support. I saw that there is only one difference: bean definitions of <code>CookieLocaleResolver</code> and <code>ReloadableResourceBundleMessageSource</code> have id attributes. So I changed the configurations to </p>
  
  <pre><code>&lt;bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"&gt;
      &lt;property name="basename" value="classpath:bundle/messageBundle" /&gt;
  &lt;/bean&gt;
  &lt;bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver"&gt;
      &lt;property name="defaultLocale" value="vi" /&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>Now it's working well!</p>
  
  <p>Do <code>ReloadableResourceBundleMessageSource</code> and <code>CookieLocaleResolver</code> require to have ids in their definitions?</p>
  
  <p>Why doesn't <code>InternalResourceViewResolver</code> need an id?</p>
  
  <p>Wondering if anyone can give me an explanation in details.</p>