簡體   English   中英

Spark + Velocity:無法加載資源(ResourceNotFoundException)

[英]Spark + Velocity: Unable to load resources (ResourceNotFoundException)

我目前正在使用 Spark 並嘗試根據文檔通過 Velocity 使用模板。

但是,我遇到了一些錯誤,有人可以提供有關如何成功加載模板的指導嗎?

Aug 22, 2017 2:26:43 PM org.apache.velocity.runtime.log.JdkLogChute log
SEVERE: ResourceManager : unable to find resource 'www/templates/template.html' in any resource loader.
[qtp1951434327-14] ERROR spark.http.matching.GeneralError - 
org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'www/templates/template.html'
public class Minimal {
        
    public static void main(String[] args) {
        get("test", (req, res) -> {
            Map<String, Object> model = new HashMap<>();
            return render(model, "www/templates/template.html");
        });
    }
        
    public static String render(Map<String, Object> model, String path) {
        return new VelocityTemplateEngine().render(new ModelAndView(model, path));
    }
}

我已經閱讀並嘗試了許多 Stack Overflow 問題的解決方案,但似乎沒有一個對我有幫助。

一些解決方案包括設置屬性,或具有特定的項目結構等。盡管這些解決方案似乎都沒有解決問題,並導致相同的異常。

您需要將模板放在資源文件夾中。 見spark中的例子,可以看到maven的pom資源定義。

暫無
暫無

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

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