当我尝试使用初始化速度引擎时
VelocityEngine engine = new VelocityEngine();
engine.init();
当我尝试时遇到同样的错误
Velocity.init();
org.apache.velocity.exception.VelocityException: Failed to initialize an instance of org.apache.velocity.runtime.log.ServletLogChute with the current runtime configuration.
什么可能导致此异常?
最佳答案
尝试这样的事情:
Properties p = new Properties();
p.setProperty("resource.loader", "class");
p.setProperty("class.resource.loader.description", "Velocity Classpath Resource Loader");
p.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
try {
Velocity.init(p);
} catch(...., and handle excpetion
}
您现在可以调用:
VelocityContext vContext = new VelocityContext(context);
//put things into vContext
StringWriter sw = new StringWriter();
try {
template.merge(vContext, sw);
等等
关于java - Apache Velocity 无法初始化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1586133/