Reputation: 15
I am building a project using spring mvc 3.1 jars, after configuring i18n folder, tomcat is throwing me the following exception :
org.apache.jasper.JasperException: javax.servlet.ServletException: javax.servlet.jsp.JspTagException: No message found under code 'label.title' for locale 'en_US'.
I have tried adding the i18n folder to classpath in eclipse(Juno), placed messages*.properties files under WEB-INF/i18n, WEB-INF/classes/i18n, WEB-INF/classes, WEB-INF/lib, WEB-INF/ but to no use.
spring-context.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<annotation-driven />
<resources location="/, classpath:/META-INF/web-resources/"
mapping="/resources/**" />
<default-servlet-handler />
<beans:bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
<context:component-scan base-package="com.hoe.spring.controller" />
<interceptors>
<beans:bean
class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"
p:paramName="lang" />
</interceptors>
<beans:bean
class="org.springframework.context.support.ReloadableResourceBundleMessageSource"
id="messageSource" p:basenames="WEB-INF/i18n/messages, WEB-INF/i18n/application"
p:fallbackToSystemLocale="false" p:fileEncodings="UTF-8"
p:defaultEncoding="UTF-8" />
<beans:bean class="org.springframework.web.servlet.i18n.CookieLocaleResolver"
id="localeResolver" p:cookieName="locale" />
</beans:beans>
messages.properties
label.title=Contact_Manager
label.firstname=First_Name
label.lastname=Last_Name
label.email=Email
label.telephone=Telephone
page.jsp
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<spring:message code=**"label.title"** var="cName"/>
label.addcontact=Add_Contact
label.menu=Menu
What am I missing ? Thanks in advance.
Upvotes: 0
Views: 5808
Reputation: 579
I struggled with same problem and what I realized is that messages_{}.properties must be in classpath. so, you do not need to mention basename property value "classpath:messages". Instead just mention "messages". here is my full configuration.
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename" value="messages"/>
<property name="useCodeAsDefaultMessage" value="true"/>
<property name="defaultEncoding" value="UTF-8" />
</bean>
<!-- allow localization through cookie and add interceptor to allow changes to locale -->
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver" />
<mvc:interceptors>
<bean id="localeChangeInterceptor"
class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="lang"/>
</bean>
</mvc:interceptors>
Upvotes: 0
Reputation: 15
I have placed the files under resources/i18n folder.
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:i18n/messages" />
<property name="defaultEncoding" value="UTF-8" />
Upvotes: 1
Reputation: 3037
Try putting the files under resources/i18n
folder of your eclipse and then use p:basenames="classpath:i18n/messages"
.
Upvotes: 0
Reputation: 708
You can try to change the message.properties file name to messages_en_US.properties
Upvotes: 0
Reputation: 708
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basenames">
<list>
<value>locale.messages</value>
<value>locale.validation.messages</value>
<value>locale.email.messages</value>
</list>
</property>
</bean>
And put the property files under locale folder(same as package structure) If it is maven/gradle project the locale folder comes under resource folder locale.validation.message => locale/validation/messages_en_US.properties
Upvotes: 0