问题描述
我有一个Spring / JSF Web应用程序,它有一个模块使用Freemarker模板的依赖。这是我做的集成:
我将applicationContext-freemarker-module.xml导入applicationContext.xml
我将配置bean添加到applicationContext-freemarker -module.xml如下。
< bean id =freemarkerConfigurationclass =org.springframework.ui.freemarker。 FreeMarkerConfigurationFactoryBean>
< property name =templateLoaderPathvalue =classpath *://>
< / bean>
我把我的模板放到freemarker模块的src / main / resources目录。
我正在读如下模板:
ApplicationContext context = new ClassPathXmlApplicationContext(applicationContext-freemarker-module.xml );
配置templateConfig =(配置)context.getBean(freemarkerConfiguration);
模板template = templateConfig.getTemplate(template.ftl);
现在我试过这么多的templateLoaderPath属性的值,但我总是得到模板未找到。例外。
Freemarker模块的JAR如下
template.ftl
applicationContext-freemarker-module.xml
com /.../(classes)
META-INF
在哪里应该放置模板文件,我应该为templateLoaderPath设置什么值?
我不明白为什么template.ftl无法找到。我试图设置正确的价值多个小时。
非常感谢您的帮助,
-
在您的* -action servlet xml FreeMarkerConfigurationFactoryBean配置中有preferFileSystemAccess属性设为false
-
< property name =templateLoaderPathvalue =classpath *://>应为
< property name =templateLoaderPathvalue =classpath://>
-
您有JAR文件在WEB-INF / lib文件夹下。 p>
-
最后,您的模板文件位于jar文件的根目录下。
I have a Spring/JSF Web application which has a dependency to a module uses Freemarker templates. Here is what i did for integration:
I imported the applicationContext-freemarker-module.xml to applicationContext.xmlI added the configuration bean to applicationContext-freemarker-module.xml like below.
<bean id="freemarkerConfiguration" class="org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean">
<property name="templateLoaderPath" value="classpath*:/"/>
</bean>
I put my templates to src/main/resources directory of freemarker module.I am reading the templates like below:
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext-freemarker-module.xml");
Configuration templateConfig = (Configuration) context.getBean("freemarkerConfiguration");
Template template = templateConfig.getTemplate("template.ftl");
Now i tried so many values for templateLoaderPath property but i always got the "Template not found." exception.
Freemarker module's JAR is like below
template.ftl
applicationContext-freemarker-module.xml
com/.../ (classes)
META-INF
Where should i put the template files and what should i set for templateLoaderPath value?I could not understand why "template.ftl" can not be found. I am trying to set the right value for many hours. I tried various path configurations without success.
Thanks a lot for your help,
Make sure you have the following
In your *-action servlet xml FreeMarkerConfigurationFactoryBean configuration has the "preferFileSystemAccess" property set to "false"
<property name="templateLoaderPath" value="classpath*:/"/> should be<property name="templateLoaderPath" value="classpath:/"/>
In freemarker the template loader tries to match a string "classpath:" , not "classpath*:"
you have the JAR file under WEB-INF/lib folder.
Finally, your template file under root of the jar file.
这篇关于弹簧Freemarker配置,找不到模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!