I am learning spring. I tried to under the use of ResourceBundleMessageSource and here is the example I tried.
Main App
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>
messages_en_US.properties
s.wish=good morning, name : {0}, school : {1}
messages_fr_FR.properties
s.wish=bonjour, name : {0}, school : {1}
output:
English... good morning, name : saro, school : stanes
French... bonjour, name : saro, school : stanes
From the docs I understand ReloadableResourceBundleMessageSource is way more advance than ResourceBundleMessageSource.
1) It is not restricted to read .properties files alone but can read xml property files as well.
2) It is not restricted to reading files from just classpath but from any location.
What is the concept around "cacheSeconds"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource ">
<property name="basename" value="resources/locale/messages"/>
<property name="cacheSeconds" value="3600"/>
</bean>
Could anyone brief on that or help me with an example to understand better.