Java Reference
In-Depth Information
<bean id="cashier1" class="com.apress.springenterpriserecipes.shop.Cashier">
<property name="name" value="cashier1" />
<property name="path" value="c:/cashier" />
</bean>
</beans>
Or you can simply include the <context:annotation-config> element in your bean configuration file
and a CommonAnnotationBeanPostProcessor instance will automatically get registered. But before this tag
can work, you must add the context schema definition to your <beans> root element.
<beans xmlns=" http://www.springframework.org/schema/beans"
xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance"
xmlns:context=" http://www.springframework.org/schema/context"
xsi:schemaLocation=" http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:annotation-config />
...
</beans>
1-8. Resolving Text Messages
Problem
For an application to support internationalization (I18N for short because there are 18 characters
between the first character, i , and the last character, n ), it requires the capability of resolving text
messages for different locales.
Solution
Spring's application context can resolve text messages for a target locale by their keys. Typically, the
messages for one locale should be stored in one separate properties file. This properties file is called a
resource bundle .
MessageSource is an interface that defines several methods for resolving messages. The
ApplicationContext interface extends this interface so that all application contexts can resolve text
messages. An application context delegates the message resolution to a bean with the exact name
messageSource . ResourceBundleMessageSource is the most common MessageSource implementation that
resolves messages from resource bundles for different locales.
How It Works
As an example, you can create the following resource bundle, messages_en_US.properties , for the
English language in the United States. Resource bundles will be loaded from the root of the classpath.
alert.checkout=A shopping cart has been checked out.
To resolve messages from resource bundles, you use ResourceBundleMessageSource as
your MessageSource implementation. This bean's name must be set to messageSource for the
 
Search WWH ::




Custom Search