无法在将另一个vm文件包含到速度模板中时找到资源

时间:2015-09-18 14:10:51

标签: java include velocity template-engine

我有以下代码:

public class EmailService {
        static {
        Velocity.setProperty("resource.loader", "class");
        Velocity.setProperty("class.resource.loader.class",
                "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
        Velocity.init();

        try {
            InputStream in = EmailService.class.getClassLoader()
                    .getResourceAsStream("support.properties");
            Properties prop = new Properties();
            prop.load(in);
            SUPPORT_EMAIL = prop.getProperty("mail", "");
        } catch (IOException e) {
            throw new RuntimeException("IOException while reading support.properties");
        }
    }

    ....


    private String getResultString(VelocityContext context, Template velocityTemplate) {
        StringWriter writer = new StringWriter();
        velocityTemplate.merge(context, writer);
        return writer.toString();
    }
}

执行行时:

velocityTemplate.merge(context, writer);

我看到以下错误:

Method threw 'org.apache.velocity.exception.ResourceNotFoundException' exception.
....
Unable to find resource 'footer.vm'

我的模板如下所示:

trololo
#include("footer.vm")

这两个模板位于文件系统附近。 enter image description here 如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

替换路径后工作

#include("velocityTemplates/footer.vm")