- Mastering Spring 5.0
- Ranga Rao Karanam
- 100字
- 2021-07-02 22:12:19
Message bundle setup
First, let's set up a message bundler. The code snippet from the spring context is as follows:
<bean id="messageSource" class=
"org.springframework.context.support.
ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:messages" />
<property name="defaultEncoding" value="UTF-8" />
</bean>
Important points to note are as follows:
- class="org.springframework.context.support.ReloadableResourceBundleMessageSource": We are configuring a reloadable resource bundle. Support reloading properties through the cacheSeconds setting.
- <property name="basename" value="classpath:messages" />: Configure the loading of properties from the messages.properties and messages_{locale}.properties file. We will discuss the locale soon.
Let's configure a couple of property files and make them available in the src/main/resources folder:
message_en.properties
welcome.caption=Welcome in English
message_fr.properties
welcome.caption=Bienvenue - Welcome in French
We can display the message from the message bundle in a view using the spring:message tag:
<spring:message code="welcome.caption" />