easyroom 2011-10-31 17:31
浏览 377
已采纳

使用junit运行freemarker找不到模板

我们是jsp项目,使用spring装配freemarker,在跑项目的时候正常,但是在跑testcase的时候报找不到模板

[color=brown]配置文件如下[/color]

<!-- 配置模板加载路径 -->
<!-- 设置FreeMarker环境属性-->

1 <!-- 刷新模板的周期,单位为秒 -->
<!--true--> <!-- 此属性可以防止模板解析空值时的错误 -->
UTF-8<!--模板的编码格式 -->

zh_CN<!-- 本地化设置-->

UTF-8
yyyy-MM-dd HH:mm:ss
yyyy-MM-dd
HH:mm:ss

0.######

true,false

<!--"/spring.ftl" as spring

true

auto_detect -->




项目是使用myeclipse向导创建的Web项目
[color=brown]配置文件的路径为[/color] /WebRoot/WEB-INF/templates/page/index.ftl
获得template的java代码如下
Template t = freemarkerConfig.getConfiguration().getTemplate("[color=red]/WEB-INF/templates/page/index.ftl[/color]");
顺便说一下,我还尝试过
Template t = freemarkerConfig.getConfiguration().getTemplate("[color=red]/WebRoot/WEB-INF/templates/page/index.ftl[/color]");
Template t = freemarkerConfig.getConfiguration().getTemplate("[color=red]/templates/page/index.ftl[/color]");
Template t = freemarkerConfig.getConfiguration().getTemplate("[color=red]D:/myproject/WebRoot/WEB-INF/templates/page/index.ftl[/color]");

再顺便说一下,我已经诅咒过spring得freemarker插件一万遍了,也没有啥用。

任何帮助或建议都不胜感激。

  • 写回答

3条回答 默认 最新

  • fmjsjx 2011-11-01 11:31
    关注

    [quote]
    是的,使用clapass是ok的,但是这里有一个情况,目录结构已经定了。配置文件时放在WEB-INF下的。这个我是没有权利改变的。有什么变通的方法么?
    [/quote]
    没让你改变目录结构啊……
    你不就只是用JUNIT跑个testcase么?
    直接在src/test/resources下建个templates目录,把/WEB-INF/templates下的文件啊文件夹什么的都拷贝一份过去不就结了?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)