Spring MessageSource

How to use Spring MessageSource:

org.springframework.context.MessageSource  # interface
org.springframework.context.support.ResourceBundleMessageSource #impl

Add to Maven:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context-support</artifactId>
    <version>3.2.4.RELEASE</version>
</dependency>

XML:

  <bean id="messageSource"
        class="org.springframework.context.support.ResourceBundleMessageSource">
    <property name="basename" value="messages"/>

Add messages.properties to classpath

Use in POJO:

@Autowired
 private MessageSource messageSource;
 ....
 messageSource.getMessage(lookup_code, args, Locale.ENGLISH)

————–

Use in JSP:

<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<spring:message code="greeting" />

via: http://www.coderanch.com/t/489232/Spring/spring-message-tag-labels-java

Advertisements
Tagged with: , ,
Posted in Spring

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: