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

标签 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 以使用它。

最佳答案

想通了。它在我编辑 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 属性。)

关于java - 如何在 Java/Spring 中自动重新加载 messages.properties 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18152819/

相关文章:

java - 在 Cacheable 注释中的条件下,如何使用 key

Java - SimpleDateFormat 意外的解析行为

javascript - 内容安全策略:拒绝执行内联脚本

tomcat - [Catalina home]/catalina.sh : -Dcom. sun.management.jmxremote=: 未找到 Tomcat(VM 选项)IntelliJ

java - 如何在不对 URL 进行硬编码的情况下调用我的 REST API get 方法?

java - JMeter安装

java - 从多个 Web 应用程序创建单个 Web 应用程序 (WAR)

Java mapToInt 与 Reduce with map

java - Android 向上按钮不起作用

java - 使用注释时忽略 `web.xml` 中的过滤器顺序?