How can i load nested folders for FreeMarker template using spring org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean

风流意气都作罢 提交于 2019-12-25 07:51:55

问题


Hi I have requirement to create ftl for different entities,

I want to load ftl's from nested folders, Like all A realted ftl's should be insite A folder then all the Macro's live into Macro folder.

<bean id="freeMarkerConfigurationFactory" class="org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean">
    <property name="templateLoaderPath" value="classpath:freemarker/Account/"/>
    <property name="preferFileSystemAccess" value="false"/>
</bean>

this is not working.Using spring 4

<bean id="freeMarkerConfigurationFactory" class="org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean">
    <property name="templateLoaderPath"> 
        <value> "classpath:freemarker/Account/" , "classpath:freemarker/Macro/"</value>
    </property>
    <property name="preferFileSystemAccess" value="false"/>
</bean>

Also after debugging the spring class

public void setTemplateLoaderPath(String templateLoaderPath) {
    this.templateLoaderPaths = new String[] {templateLoaderPath};
}

Instead of an array , templateLoaderPath behaves like single string.


回答1:


You need to set the templateLoaderPaths property (note the s at the end), not templateLoaderPath.

I believe the Spring syntax for that will be (haven't tested it...):

<property name="templateLoaderPaths"
          values="classpath:freemarker/Account/,classpath:freemarker/Macro/"
/>

or the longer form:

<property name="templateLoaderPaths">
  <array>
    <value>classpath:freemarker/Account/</value>
    <value>classpath:freemarker/Macro/</value>
  </array>
</property>


来源:https://stackoverflow.com/questions/36330590/how-can-i-load-nested-folders-for-freemarker-template-using-spring-org-springfra

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!