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

时间:2013-08-09 17:58:05

标签: java spring tomcat spring-mvc

我一直在使用Java / Spring使用#springMessage()标签和message.properties文件的国际网站上工作。请参阅我最近的问题:In Java/Spring, how to gracefully handle missing translation values?

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

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

1 个答案:

答案 0 :(得分: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>

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