Announcement Announcement Module
No announcement yet.
i18n - Can't find bundle for base name messages Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • i18n - Can't find bundle for base name messages

    I'm hoping one of you brilliant Spring developers will be able to help me with this. I've been stuck all day, researching docs and online tips, to no avail.

    Want to support i18n internationalization in a simple test Spring MVC web app using the messages in a JSP.

    My files are in /src/main/webapp/resources/international/. I currently have and

    I've tried every combination of messageSource basename I can think of in my servlet-context.xml file, and I always get the error "nested exception is java.util.MissingResourceException: Can't find bundle for base name messages, locale en_US".

    Here's my ../WEB-INF/spring/appServlet/servlet-context.xml file:

    <?xml version="1.0" encoding="UTF-8"?>
    <beans:beans xmlns=""
    	<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
    	<!-- Enables the Spring MVC @Controller programming model -->
    	<annotation-driven />
    	<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
    	<resources mapping="/resources/**" location="/resources/" />
    	<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
    	<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    		<beans:property name="prefix" value="/WEB-INF/views/" />
    		<beans:property name="suffix" value=".jsp" />
    	<!-- Support i18n message bundles -->
    	<beans:bean id="messageSource" class="">
    		<!-- This is the path to where the property file is located, plus base name of the properties file (messages, ex: the bean will expand to -->
    		<beans:property name="basename" value="classpath:/resources/international/messages" />
    		<beans:property name="cacheSeconds" value="1" />
    		<beans:property name="defaultEncoding" value="UTF-8" /> 
    		<beans:property name="fallbackToSystemLocale" value="true" />
    	<context:component-scan base-package="com.mydomain.myapp" />	
    I've tried all of the following:
    <beans:property name="basename" value="classpath:/resources/international/messages" />
    <beans:property name="basename" value="/resources/international/messages" />
    <beans:property name="basename" value="resources/international/messages" />
    <beans:property name="basename" value="./resources/international/messages" />
    <beans:property name="basename" value="../resources/international/messages" />
    and have even tried moving the properties files to WEB-INF with appropriate basename - no change.

    My NavigationController, which I don't beleive is the issue, is:
    Locale locale = Locale.getDefault();
    ResourceBundle resources = ResourceBundle.getBundle("messages", locale);
    Does anyone have any idea what I'm doing wrong here? Greatly appreciate ANY help, guidance, or assistance.


  • #2
    If it is feasible for your project, I would recommend moving src/main/webapp/resources under src/main/webapp/WEB-INF. Then, you should change your message source bean definition to:

        <bean id="messageSource" class="">
            <property name="basenames">
            <property name="defaultEncoding" value="ISO-8859-1" />
            <property name="fallbackToSystemLocale" value="false" />


    • #3
      Thanks, Manish. The actual issue *was* the controller. But I did move the properties files to a directory under WEB-INF. Appreciate the feedback!


      • #4
        Manish, do you have any resources on the best practice for handling language-specific views? For pages with a lot of text, or html formatting, this gets unwieldy. I'm guessing something like ../views/en_us/wordypage.jsp, with a view resolver that manages this?


        • #5
          Are you referring to the fact that when a page is mostly content-only, storing its content in i18 files is cumbersome? If this is the concern, and if a page will always have content in a single language only, I would just put the content in the page's view itself rather than externalizing it to an i18 file.

          If however, the page content can be vary by locale and storing all the content in i18 files is a problem, I would migrate the content to a proper content management system (CMS). Then, it will be a matter of writing an implementation of the MessageSource interface to fetch content from the CMS.


          • #6
            The content page would have to support multiple languages; an FAQ page would be a decent example. I would think storing separate pages (or at lease separate JSP includes) would be more manageable than a message bundle (again, when there is heavy HTML formatting or custom images involved).

            I would expect a filesystem similar to:


            And that a locale-sensitive view resolver would know how to set the language, so that the controller would just return "faq" and the resolver would direct it to the correct jsp page. Something similar to or derived from org.springframework.web.servlet.i18n.LocaleChangeI nterceptor.

            If something exists that does that, I haven't been able to find it. And don't want to create my own if it already exists out there. I can't be the first person to need this.

            And thanks for your help!


            • #7
              I suggest you take a look at the different view resolver implementations... Especially the ResourceBundleViewResolver, which works in a similair way as the ResourceBundleMessageSource.


              • #8
                Thanks, Marten. I think that's what I was looking for. Greatly appreciate the tip.