title: Cannot locate message in MessageSource
body: <p>I am trying to get one simple spring application running but getting following exception:</p>
  
  <blockquote>
    <p>javax.servlet.ServletException: javax.servlet.jsp.JspTagException: No
    message found under code 'label.firstname' for locale 'en_US'.</p>
  </blockquote>
  
  <p>My contact.jsp file:</p>
  
  <pre><code>&lt;%@taglib uri="http://www.springframework.org/tags" prefix="spring"%&gt;
  &lt;%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%&gt;
  &lt;%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %&gt;
  &lt;%@ page isELIgnored="false" %&gt;
  
  &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;Spring 3 MVC Series - Contact Manager | viralpatel.net&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;h2&gt;Contact Manager&lt;/h2&gt;
  
  &lt;form:form method="post" action="add.html" commandName="contact"&gt;
  
      &lt;table&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;form:label path="firstname"&gt;&lt;spring:message code="label.firstname"/&gt;&lt;/form:label&gt;&lt;/td&gt;
          &lt;td&gt;&lt;form:input path="firstname" /&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;form:label path="lastname"&gt;&lt;spring:message code="label.lastname"/&gt;&lt;/form:label&gt;&lt;/td&gt;
          &lt;td&gt;&lt;form:input path="lastname" /&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;form:label path="email"&gt;&lt;spring:message code="label.email"/&gt;&lt;/form:label&gt;&lt;/td&gt;
          &lt;td&gt;&lt;form:input path="email" /&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;form:label path="telephone"&gt;&lt;spring:message code="label.telephone"/&gt;&lt;/form:label&gt;&lt;/td&gt;
          &lt;td&gt;&lt;form:input path="telephone" /&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td colspan="2"&gt;
              &lt;input type="submit" value="&lt;spring:message code="label.addcontact"/&gt;"/&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/form:form&gt;
  
  &lt;h3&gt;Contacts&lt;/h3&gt;
  &lt;c:if  test="${!empty contactList}"&gt;
  &lt;table class="data"&gt;
  &lt;tr&gt;
      &lt;th&gt;Name&lt;/th&gt;
      &lt;th&gt;Email&lt;/th&gt;
      &lt;th&gt;Telephone&lt;/th&gt;
      &lt;th&gt;&amp;nbsp;&lt;/th&gt;
  &lt;/tr&gt;
  &lt;c:forEach items="${contactList}" var="contact"&gt;
      &lt;tr&gt;
          &lt;td&gt;${contact.lastname}, ${contact.firstname} &lt;/td&gt;
          &lt;td&gt;${contact.email}&lt;/td&gt;
          &lt;td&gt;${contact.telephone}&lt;/td&gt;
          &lt;td&gt;&lt;a href="delete/${contact.id}"&gt;delete&lt;/a&gt;&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/c:forEach&gt;
  &lt;/table&gt;
  &lt;/c:if&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>My spring-servlet.xml file</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:jee="http://www.springframework.org/schema/jee" xmlns:lang="http://www.springframework.org/schema/lang"
      xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
      xmlns:util="http://www.springframework.org/schema/util"
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
          http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
          http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
          http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
          http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
          http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"&gt;
  
      &lt;context:annotation-config /&gt;
      &lt;context:component-scan base-package="net.viralpatel.contact" /&gt;
  
      &lt;bean id="jspViewResolver"
          class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
          &lt;property name="viewClass"
              value="org.springframework.web.servlet.view.JstlView" /&gt;
          &lt;property name="prefix" value="/WEB-INF/jsp/" /&gt;
          &lt;property name="suffix" value=".jsp" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="messageSource"
          class="org.springframework.context.support.ReloadableResourceBundleMessageSource"&gt;
          &lt;property name="basename" value="WEB-INF/messages" /&gt;
          &lt;property name="defaultEncoding" value="UTF-8" /&gt;
      &lt;/bean&gt;
  
  
  
      &lt;bean id="propertyConfigurer"
          class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
          p:location="/WEB-INF/jdbc.properties" /&gt;
  
  &lt;!--    &lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" --&gt;
  &lt;!--        destroy-method="close" p:driverClassName="${jdbc.driverClassName}" --&gt;
  &lt;!--        p:url="${jdbc.databaseurl}" p:username="${jdbc.username}" p:password="${jdbc.password}" /&gt; --&gt;
  
      &lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
          destroy-method="close" p:driverClassName="com.mysql.jdbc.Driver"
          p:url="jdbc:mysql://localhost:3306/ContactManager" p:username="root" p:password="12345" /&gt;
  
  
      &lt;bean id="sessionFactory"
          class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"&gt;
          &lt;property name="dataSource" ref="dataSource" /&gt;
          &lt;property name="configLocation"&gt;
              &lt;value&gt;classpath:hibernate.cfg.xml&lt;/value&gt;
          &lt;/property&gt;
          &lt;property name="configurationClass"&gt;
              &lt;value&gt;org.hibernate.cfg.AnnotationConfiguration&lt;/value&gt;
          &lt;/property&gt;
          &lt;property name="hibernateProperties"&gt;
              &lt;props&gt;
                  &lt;prop key="hibernate.dialect"&gt;${jdbc.dialect}&lt;/prop&gt;
                  &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt;
              &lt;/props&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;tx:annotation-driven /&gt;
      &lt;bean id="transactionManager"
          class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt;
          &lt;property name="sessionFactory" ref="sessionFactory" /&gt;
      &lt;/bean&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>I am hitting url:</p>
  
  <p>localhost:8080/MavenWeb-0.0.1/index</p>
  
  <p>and my server stacktrace:</p>
  
  <pre><code>SEVERE: No message found under code 'label.firstname' for locale 'en_US'.
  javax.servlet.jsp.JspTagException: No message found under code 'label.firstname' for locale 'en_US'.
      at org.springframework.web.servlet.tags.MessageTag.doStartTagInternal(MessageTag.java:184)
      at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:79)
      at org.apache.jsp.WEB_002dINF.jsp.contact_jsp._jspx_meth_spring_005fmessage_005f0(contact_jsp.java:252)
      at org.apache.jsp.WEB_002dINF.jsp.contact_jsp._jspx_meth_form_005flabel_005f0(contact_jsp.java:219)
      at org.apache.jsp.WEB_002dINF.jsp.contact_jsp._jspx_meth_form_005fform_005f0(contact_jsp.java:138)
      at org.apache.jsp.WEB_002dINF.jsp.contact_jsp._jspService(contact_jsp.java:91)
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
      at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:471)
      at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:402)
      at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:329)
      at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
      at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
      at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1047)
      at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:817)
      at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
      at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
      at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
      at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:563)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:403)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:301)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:162)
      at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
      at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
      at java.lang.Thread.run(Thread.java:662)
  </code></pre>
  
  <p><strong>Steps to get issue resolved:</strong></p>
  
  <ol>
  <li>Place messages_en.properties files in src/main/resource folder only</li>
  <li>Make sure name of file is correct as messages_en.properties and not
  message_en.properties</li>
  <li>When you do maven build using <code>mvn clean install</code>
  messages_en.properties file will appear in
  target/projectname/WEB-INF/classes/messages.properties</li>
  <li>Check in spring-servlet.xml(name may vary) and use
      classpath:messages as basename in messageSource</li>
  </ol>
  
  <p>and it should work as it resolved my issue. </p>
  
  <pre><code>&lt;bean id="messageSource"
      class="org.springframework.context.support.ReloadableResourceBundleMessageSource"&gt;
      &lt;property name="basename" value="classpath:messages" /&gt;
      &lt;property name="defaultEncoding" value="UTF-8" /&gt;
  &lt;/bean&gt;
  </code></pre>