简体   繁体   中英

How to automatically reload messages.properties files in Java/Spring?

I've been working on an interntaional website using Java/Spring using #springMessage() tags and message.properties files. See my recent question: In Java/Spring, how to gracefully handle missing translation values?

I want to be able to edit (overwrite) the messages.properties files and be able to see the new translations immedatiately in my browser (without restarting Tomcat).

I thought that http://commons.apache.org/proper/commons-configuration/userguide/howto_filebased.html#Automatic_Reloading would be what I need, but I'm not sure how to edit my webmvc-config.xml to use that.

Figured it out. It worked after I edited webmvc-config.xml:

<bean id="messageSource"
    class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
    <property name="basename">
        <value>${content.path.config}/WEB-INF/messages</value>
    </property>
    <property name="defaultEncoding" value="UTF-8" />
    <property name="cacheSeconds" value="2"/>
</bean>

(I just needed to add the cacheSeconds property.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM