Java 可重新加载的ResourceBundleMessageSource与ResourceBundleMessageSource-缓存概念;其他差异
我在学春天。 我尝试在ResourceBundleMessageSource的使用下进行测试,下面是我尝试的示例 主应用程序Java 可重新加载的ResourceBundleMessageSource与ResourceBundleMessageSource-缓存概念;其他差异,java,spring,properties-file,resourcebundle,reloadable,Java,Spring,Properties File,Resourcebundle,Reloadable,我在学春天。 我尝试在ResourceBundleMessageSource的使用下进行测试,下面是我尝试的示例 主应用程序 public class MainApp { public static void main(String arg[]){ ApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml"); String text = context.g
public class MainApp {
public static void main(String arg[]){
ApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml");
String text = context.getMessage("s.wish",
new Object[] {"saro", "stanes" },
Locale.ENGLISH);
System.out.println("English... " + text);
String text2 = context.getMessage("s.wish",
new Object[] {"saro", "stanes" },
Locale.FRANCE);
System.out.println("French... " + text2);
}
}
Beans.xml
<!-- resource bundle -->
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource ">
<property name="basename" value="resources/locale/messages"/>
</bean>
消息\u fr\u fr.properties
s.wish=good morning, name : {0}, school : {1}
s.wish=bonjour, name : {0}, school : {1}
输出:
English... good morning, name : saro, school : stanes
French... bonjour, name : saro, school : stanes
从文档中我了解到,可重新加载的ResourceBundleMessageSource比ResourceBundleMessageSource更先进
1) 它不仅限于读取.properties文件,还可以读取xml属性文件
2) 它不局限于仅从类路径读取文件,而是从任何位置读取文件
“缓存秒”的概念是什么
class="org.springframework.context.support.ReloadableResourceBundleMessageSource ">
<property name="basename" value="resources/locale/messages"/>
<property name="cacheSeconds" value="3600"/>
</bean>
class=“org.springframework.context.support.ReloadableResourceBundleMessageSource”>
有谁能简单介绍一下,或者帮我举个例子,让我更好地理解。设置缓存加载的属性文件的秒数
- 默认值为“-1”,表示永久缓存(就像java.util.ResourceBundle一样)
- 正数将在给定的秒数内缓存加载的属性文件。这本质上是刷新检查之间的间隔。 请注意,刷新尝试将首先检查文件的最后修改时间戳,然后再实际重新加载它;所以,如果文件没有更改,这个间隔可以设置得很低,因为刷新尝试实际上不会重新加载
- 值“0”将在每次消息访问时检查文件的最后修改时间戳。请勿在生产环境中使用此选项李>