现有路径上的 ResourceNotFoundException
ResourceNotFoundException on existing path
我有以下 class:
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
确实存在于我的机器上,如果键入复制的路径到地址行,我可以导航到它。
不要使用完整的绝对路径,而是从类路径加载它,因为它已经在 类 文件夹中。
subjectTemplate =
Velocity.getTemplate("velocityTemplates/terminalModerationStatusChanged.vm", "UTF-8");
我有以下 class:
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
确实存在于我的机器上,如果键入复制的路径到地址行,我可以导航到它。
不要使用完整的绝对路径,而是从类路径加载它,因为它已经在 类 文件夹中。
subjectTemplate =
Velocity.getTemplate("velocityTemplates/terminalModerationStatusChanged.vm", "UTF-8");