Question

I am trying to use freemarker template using spring, my spring config is give below,

<bean id="freemarkerConf" class="org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean" >
    <!-- Turn this off to always load via SpringTemplateLoader -->
    <property name="preferFileSystemAccess" value="false"></property>
    <property name="templateLoaderPath" value="classpath:/WEB-INF/freemarker/alertmail/"></property>
</bean>

but for some reason I keep getting the following exception,

java.io.FileNotFoundException: Template mainMail.ftl not found.
at freemarker.template.Configuration.getTemplate(Configuration.java:489)
at freemarker.template.Configuration.getTemplate(Configuration.java:466)

My code is as below,

mailBody = FreeMarkerTemplateUtils.processTemplateIntoString(freemarkerConf.getTemplate("mainMail.ftl","UTF-8"), model);

My templates are located in a folder under the classpath.

Was it helpful?

Solution

Make sure files are under: src/freemarker/alermail and then

    <bean id="freemarkerConf" class="org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean" >
        <!-- Turn this off to always load via SpringTemplateLoader -->
        <property name="preferFileSystemAccess" value="false"></property>
        <property name="templateLoaderPath" value="classpath:/freemarker/alertmail/"></property>
    </bean>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top