1
對我有下面的類:ResourceNotFoundException現有路徑
public class EmailService {
static {
Velocity.setProperty("resource.loader", "class");
Velocity.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
Velocity.init();
}
public void sendTerminalModerationStatusChangedEmail(Terminal terminal, String to) {
...
Template subjectTemplate = null;
try {
subjectTemplate = Velocity.getTemplate(existedPath, "UTF-8");
} catch (URISyntaxException e) {
e.printStackTrace();
}
...
}
}
在調試我看到存在的路徑確實存在。但我得到了以下錯誤:
Unable to find resource 'C:/Program Files (x86)/apache/apache-tomcat-7.0.52/webapps/ROOT/WEB-INF/classes/velocityTemplates/terminalModerationStatusChanged.vm'
但文件C:/Program Files (x86)/apache/apache-tomcat-7.0.52/webapps/ROOT/WEB-INF/classes/velocityTemplates/terminalModerationStatusChanged.vm
真的存在於我的mashine如果類型路徑複製到地址線,我可以找到它。
爲什麼你使用完整路徑,而不是像'velocityTemplates/terminalModerationStatusChanged.vm'一樣從類路徑引用加載它? – K139
@ K139你是對的 – gstackoverflow
好的,加入它作爲答案then.Thanks! – K139