how to use messages with freemarker in spring mvc?

Blankman picture Blankman · Jul 1, 2010 · Viewed 14.5k times · Source

In a .jsp I would use:

<fmt:message key="welcome.title"/>

to display a message from my messages.properties file.

How would I do this with freemarker ?

Answer

Arthur Ronald picture Arthur Ronald · Jul 1, 2010

Import Spring Macro

<#import "/spring.ftl" as spring/>

Then

<@spring.message "yourMessageKeyGoesHere"/>

But you need to register ResourceBundleMessageSource

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

Keep in mind MessageSource must be called messageSource