Announcement Announcement Module
Collapse
No announcement yet.
How do you use ReloadableResourceBundleMessageSource? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How do you use ReloadableResourceBundleMessageSource?

    Hello,

    I am trying to use a ReloadableResourceBundleMessageSource and have it defined in my main applicationContext file like so:

    Code:
    <bean id="baseMessageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
    		<property name="basename"><value>messages</value></property>
    	</bean>
    	
    	<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
    		<property name="basenames"><value>dynamicMessages</value></property>
    		<property name="parentMessageSource"><ref bean="baseMessageSource"/></property>
        	<property name="cacheSeconds"><value>0</value></property>
    	</bean>
    When I try to pull a code from the dynamicMessages property file using <spring:message> I get an error that it cannot find the code, even though the code is in the file. Am I doing something wrong? How can I get the web tier to use the reloadable property file?

    Thanks for any help,

    Rexxe

  • #2
    Where is the dynamicMessages properties file located? The 'basenames' property of ReloadableResourceBundleMessageSource is treated differently from that of ResourceBundleMessageSource. Check out javadocs of ReloadableResourceBundleMessageSource.

    For example if your dynamicMessages file is located under WEB-INF/i18n/ then the 'basenames' property of your ReloadableResourceBundleMessageSource bean should look like

    Code:
    <property name="basenames">
       <value>/WEB-INF/i18n/dynamicMessages</value>
    </property>

    Hope this helps,
    Sanjiv

    Comment


    • #3
      Thanks, that was indeed the problem.

      Comment


      • #4
        That's how I have my ReloadableResourceBundleMessageSource defined in the applicationContext file as follows:
        Code:
        <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">        
                <property name="basename" value="/WEB-INF/classes/messages"/>
                <property name="defaultEncoding" value="UTF-8"/>
            </bean>
        how do I call messages outta that message file from a JAVA class using the MessageSourceAccessor. I can do it successfully from a JSP page using <spring:message code="test.test"/>.

        Thanks in advance

        Comment


        • #5
          And how can we default to the plain basenames file i.e. dynamicMessages? I recently got an error when my class called getMessage on the Reloadable...
          class and got this exception because the Australian resource bundle was not found. Thats dumb because it should default to dynamicMessages.properties

          org.springframework.context.NoSuchMessageException : No message found under code 'bean.Order.price' for locale 'en_AU'.

          Comment

          Working...
          X