Spring Freemarker配置,找不到模板

Spring Freemarker配置,找不到模板
我有一个 Spring / JSF Web应用程序,它依赖于模块使用Freemarker模板.这是我为整合做的事情:

我将applicationContext-freemarker-module.xml导入applicationContext.xml
我将配置bean添加到applicationContext-freemarker-module.xml,如下所示.

<bean  >   <property name="templateLoaderPath" value="classpath*:/"/> </bean>

我把模板放到freemarker模块的src / main / resources目录下.
我正在阅读如下模板:

ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext-freemarker-module.xml");Configuration templateConfig = (Configuration) context.getBean("freemarkerConfiguration");Template template = templateConfig.getTemplate("template.ftl");

现在我为templateLoaderPath属性尝试了很多值,但我总是得到“找不到模板”.例外.

Freemarker模块的JAR如下所示

template.ftlapplicationContext-freemarker-module.xmlcom/.../ (classes)META-INF

我应该在哪里放模板文件,我应该为templateLoaderPath值设置什么?
我无法理解为什么找不到“template.ftl”.我试图设置正确的值数小时.我尝试了各种路径配置但没有成功.

非常感谢你的帮助,

确保您拥有以下内容

>在* -action servlet中,xml FreeMarkerConfigurationFactoryBean配置将“preferFileSystemAccess”属性设置为“false”
>< property name =“templateLoaderPath”value =“classpath *:/”/>应该
< property name =“templateLoaderPath”value =“classpath:/”/>

在freemarker中,模板加载器尝试匹配字符串“classpath:”,而不是“classpath *:”>您在WEB-INF / lib文件夹下有JAR文件.>最后,您的模板文件位于jar文件的根目录下.

免责声明:本网信息来自于互联网,目的在于传递更多信息,并不代表本网赞同其观点。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,并请自行核实相关内容。本站不承担此类作品侵权行为的直接责任及连带责任。如若本网有任何内容侵犯您的权益,请及时联系我们,本站将会在24小时内处理完毕。
相关文章
返回顶部