1
votes

I am trying to load Freemarker templates from multiple locations using Spring MVC. This project is developed using Intellij.

I have two maven projects:

  • my-website: the main maven project, contains customised templates at WEB-INF/ftl, example, WEB-INF/ftl/landing/login.ftl

  • generic-templates: that contains the generic freemarker templates at WEB-INF/ftl, example, WEB-INF/ftl/landing/login.ftl

The idea is for Freemarker, for example, to search for landing/login in 'my-website' and if it is not found then search it in 'generic-templates' landing/login.

According to the freemarker template loader documentation the freemarker.xml should look like:

    <bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
        <property name="templateLoaderPaths" value="generic-templates://WEB-INF/ftl/,/WEB-INF/ftl/" />
    </bean>

    <bean id="viewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
        <property name="cache" value="true"/>
        <property name="prefix" value=""/>
        <property name="suffix" value=".ftl"/>
    </bean>

but I am obviously doing something very wrong because it is not working: the files for generic-templates are not found.

Any idea how can I make this work ? (other approaches that accomplish the same goal are welcomed)

How can I debug it ?

1
Did you manage to make this work? - Vojtěch

1 Answers

0
votes

The scheme part (the part before and including the :) is something that some integrating frameworks utilize via their custom TemplateLoader-s, while others don't. Interpreting the scheme is not done by FreeMarker itself. Furthermore, Spring has its own ideas about schemes in resource paths, which might interfere with this mechanism.

However one customizes things, the scheme shouldn't refer to a Maven module name, as Maven modules don't really exist on runtime. Instead, you should put the two group of templates under different directories under WEB-INF, and then list both paths in templateLoaderPaths, similarly as you did.