我有以下代码:
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")
答案 0 :(得分:0)
替换路径后工作
#include("velocityTemplates/footer.vm")