Ok, finally I solve my problem by passing whole resource and local object to velocity.
In my email service class, I did this:
Code:
Map model = new HashMap();
model.put("user", user);
model.put("resources",this.resource);
model.put("locale", this.locale);
String text = VelocityEngineUtils.mergeTemplateIntoString(
velocityEngine, "email.html", model);
....
public void setResource(ResourceBundleMessageSource resource){
this.resource = resource;
}
In the email template :
Code:
<html>
<body>
<h1>#msg("label.welcome")</h1>
In macro.vm
Code:
#macro(msg $code)
$resources.getMessage($code,null,$locale)
#end
spring config:
Code:
<bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFactoryBean">
<property name="velocityProperties">
<props>
<prop key="resource.loader">class</prop>
<prop key="class.resource.loader.class">
org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
</prop>
<prop key="velocimacro.library">velocity/macro.vm</prop>
</props>
</property>