如何在Java/Spring中自动重新加载messages.properties文件?

Rya*_*yan 1 java spring tomcat spring-mvc

我一直在使用Java/Spring使用#springMessage()标签和message.properties文件在interntaional网站上工作.请参阅我最近的问题:在Java/Spring中,如何优雅地处理缺失的翻译值?

我希望能够编辑(覆盖)messages.properties文件,并能够在我的浏览器中立即查看新的翻译(无需重新启动Tomcat).

我认为http://commons.apache.org/proper/commons-configuration/userguide/howto_filebased.html#Automatic_Reloading将是我需要的,但我不知道如何编辑我的webmvc-config.xml来使用它.

Rya*_*yan 8

弄清楚了.在我编辑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>
Run Code Online (Sandbox Code Playgroud)

(我只需要添加cacheSeconds属性.)