1

只是尝试使用 Spring 3.2 测试框架的新特性,以便在 Web 层进行真正的集成测试。在 Spring 3.2 中使用“SpringJUnit4ClassRunner”触发测试时遇到问题,因为模板引擎抱怨无法解析模板名称:

2013-06-28 09:29:18,372 ERROR TemplateEngine - [THYMELEAF][main] Exception processing template "mobile/index": Error resolving template "mobile/index", template might not exist or might not be accessible by any of the configured Template Resolvers

当然,引擎正在搜索/WEB-INF/views/mobile/index.html周围的资源,在正常执行模式下是正确的,但在类路径中沿着测试执行环境不存在:*classpath (src/test/resources) 在基于 Maven 的项目中 * /WEB-INF/views/mobile/index.html

有没有办法让引擎从“真实路径”中获取资源,以免在测试类路径中维护每个 html 视图的副本?

提前致谢,

4

1 回答 1

0

一种解决方案是在“/src/main/resources/views”下拥有所有视图并使用

org.thymeleaf.templateresolver.ClassLoaderTemplateResolver

这样,您在系统上就没有任何依赖关系(而不是使用“FileTemplateResolver”),并且您也不需要为测试执行上下文提供任何重复的 spring 配置文件。

对我来说,那里的观点仍然有点奇怪,但是......为什么不呢?

对资源文件夹下的视图有任何评论/建议吗?

于 2013-06-28T09:55:52.837 回答