簡體   English   中英

將另一個vm文件包含到速度模板中時找不到資源

[英]Unable to find resource while include another vm file into velocity template

我有以下代碼:

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")

這兩個模板位於文件系統附近。 在此處輸入圖片說明 如何解決這個問題?

替換路徑后工作

#include("velocityTemplates/footer.vm")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM