Velocity找不到模板

最近工做中須要用到模板解析的功能,找到了velocity,按照例子作了一遍,沒有問題,

因而乎,直接用於工做環境,發現老是報Resource not found 的異常,

檢查模板路徑,並無寫錯什麼,可是老是報這個異常,模板換了N個位置,仍是報此異常

後來拋棄   
    Velocity.init();
     Template template = Velocity.getTemplate("container.htm");

改成:

    VelocityEngine velocityEngine = new VelocityEngine();
     Properties properties = new Properties();
     String basePath = 「路徑/windows/tlp」;
     properties.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, basePath);
     velocityEngine.init(properties);

    Template template = Velocity.getTemplate("container.htm");
就能夠了

看了一下文檔,Velocity容許兩種方式:
一、全局使用一個Velocity引擎(jvm中只有一個Velocity引擎的實例),適應於配置文件等解析(路徑是一致的)
二、建立多個引擎實例,針對每一個引擎實例設置Velocity.FILE_RESOURCE_LOADER_PATH能夠使用不一樣位置的模板
相關文章
相關標籤/搜索