Sheldon R.
Sheldon R.

Reputation: 452

Spring Message Not Displaying

I am trying to do internationalization in Spring-MVC for the first time and I'm having what I assume to be a configuration issue. I have a NLS file that I named NLS_en.properties which I placed in my application's WEB-INF\classes directory. The file contains the following NLS string:

MSG_HELLO = Hello to the Internationalized World

In my application's servlet.xml file I've defined the following beans:

<bean id="localeResolver"
    class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
  <property name="defaultLocale" value="en" />
</bean>
<bean id="messageSource"
    class="org.springframework.context.support.ResourceBundleMessageSource">
  <property name="basename" value="WEB-INF/classes/NLS"/>
</bean>

In my JSP file I have the following tag:

<p><spring:message code="MSG_HELLO" text="You should not be seeing this text" />

When the JSP displays, of course, the message I see is the one I should not be seeing, so how do I have to configure my application so that I do see my HELLO message?

Upvotes: 0

Views: 2185

Answers (1)

gregdim
gregdim

Reputation: 2071

ResourceBundleMessageSource basename (as opposed to ReloadableResourceBundleMessageSource) refers by default to the classpath, so you should have it like :

<property name="basename" value="NLS" />

Now, depending on how you build, even if configuring correctly the message source, it may have been erased at the time you run the application. Do not place resources directly into classes (or any target directory in general). If you use maven place it directly into resources. If you dont use any build framework put it in the root of the source directory.

Upvotes: 1

Related Questions