【发布时间】:2011-07-28 17:12:56
【问题描述】:
我有一个 Spring/JSF Web 应用程序,它依赖于使用 Freemarker 模板的模块。这是我为集成所做的:
我将 applicationContext-freemarker-module.xml 导入到 applicationContext.xml 我将配置 bean 添加到 applicationContext-freemarker-module.xml 中,如下所示。
<bean id="freemarkerConfiguration" class="org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean">
<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.ftl
applicationContext-freemarker-module.xml
com/.../ (classes)
META-INF
我应该把模板文件放在哪里,我应该为 templateLoaderPath 值设置什么? 我不明白为什么找不到“template.ftl”。我正在尝试为多个小时设置正确的值。我尝试了各种路径配置都没有成功。
非常感谢您的帮助,
【问题讨论】:
-
你试过
<property name="templateLoaderPath" value="classpath:/"/>吗?如果 .ftl 文件位于 jar 的根目录中,这应该可以工作... -
是的,我已经尝试过了,但仍然找不到 .ftl 文件。非常感谢您的回复。
标签: spring templates configuration freemarker