ResourceBundleMessageSource和ReloadableResourceBundleMessageSource

ResourceBundleMessageSource只能读取classpath中的文件

ReloadableResourceBundleMessageSource可以读取外部文件

<bean id="messageSource"
  class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
    <property name="defaultEncoding" value="UTF-8"/>
    <property name="basenames">
        <list>
            <value>classpath:bundles/resource</value>
            <value>classpath:bundles/override</value>
            <value>file:C:/mmt/override</value>
        </list>
    </property>
</bean>
注意外部文件的写法,
file:/path/to/messages

如果要动态刷新必须加一下配置

<property name="cacheSeconds" value="100" />

否则不会动态刷新


setCacheSeconds

public void setCacheSeconds(int cacheSeconds)
Set the number of seconds to cache loaded properties files.
  • Default is "-1", indicating to cache forever (just likejava.util.ResourceBundle).
  • A positive number will cache loaded properties files for the givennumber of seconds. This is essentially the interval between refresh checks.Note that a refresh attempt will first check the last-modified timestampof the file before actually reloading it; so if files don't change, thisinterval can be set rather low, as refresh attempts will not actually reload.
  • A value of "0" will check the last-modified timestamp of the file onevery message access. Do not use this in a production environment!

猜你喜欢

转载自blog.csdn.net/liduanwh/article/details/79863024