问题
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