views:

3306

answers:

1

Hi,

In my Spring app, I'd like to use FreeMarker to generate the text of emails that will be sent by my application. The generated text will never be returned to the view so I don't need to configure a FreeMarker view resolver. The documentation seems to indicate that I should configure a FreeMarkerConfigurationFactoryBean like this

<bean id="freemarkerConfiguration" class="org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean">
   <property name="templateLoaderPath" value="/WEB-INF/freemarker/"/>
</bean>

Once I have this bean configured how do I actually get the text that is generated for a particular template, with a particular Map of variables. In other words, what code comes after:

String templateName = "email"
Map templateVars = new HashMap();
templateVars.put("firstName", "john");
templateVars.put("surname", "doe");    
// Now how do I get the template text?

Spring modules seems to provide an alternative integration between Spring and FreeMarker which makes retrieving the template text very obvious, but I'd prefer not to add an additional dependency to my app unless it's absolutely necessary.

Also, do I need to add some extra configuration to the FreeMarkerConfigurationFactoryBean to ensure that the templates are cached?

Cheers, Don

+6  A: 
Chris Serra
Thanks, presumably the variable you've named configuration is the bean I've named freemarkerConfiguration?
Don
Yes, in the class we used, the 'configuration' variable is of type 'Configuration'. See my revised post ^^
Chris Serra
still there is no configuration definition.
Ahmet Alp Balkan