找不到Freemarker模板 [英] Freemarker template not found
问题描述
我目前正试图让Freemarker使用Spring处理我的应用程序。无论我尝试什么,我都会不断找到模板。我不确定我是否正确配置了配置,但它从未找到我的模板。这是我的spring bean配置:
I'm currently trying to get Freemarker to work with my application using Spring. No matter what I try I keep getting template not found. I am not sure if I have the configuration set up properly, but it never finds my template. Here is my spring bean config:
<bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
<property name="templateLoaderPath" value="/WEB-INF/freemarker/"/>
</bean>
每当我尝试在freemaker配置上调用getTemplate时,它总是会发回模板未找到错误。所以如果我这样做
Whenever I try to call getTemplate on the freemaker configuration it always sends back a template not found error. So if I do
configuration.getTemplate("testTemplate.ftl")
它总是抛出IOException。
it always throws an IOException.
我不确定是否有人知道我做错了什么。
I'm not sure if anyone has an idea of what I'm doing wrong.
谢谢你所有你的帮助!
推荐答案
首先, / WEB-INF / freemarker
只能作为 WebApplicationContext
中的路径;否则Spring会尝试将其解析为文件系统路径而不是servlet上下文路径。您是从 DispatcherServlet
加载的上下文中发布的摘录?
First of all, /WEB-INF/freemarker
would only work as a path from within WebApplicationContext
; otherwise Spring would attempt to resolve it as file system path rather than servlet context path. Is the excerpt you've posted above from the context being loaded by DispatcherServlet
?
其次,有什么理由吗?为什么你直接使用配置
而不是使用Spring的 ViewResolver
?
Secondly, is there any reason why are you using configuration
directly instead of using Spring's ViewResolver
?
最后, IOException
可能意味着许多不同的事情。你可以发一个完整的堆栈跟踪吗?
Finally, IOException
can mean many different things. Can you post a full stack trace?
这篇关于找不到Freemarker模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!