java - Apache Velocity 无法初始化

标签 java velocity

当我尝试使用初始化速度引擎时

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/

相关文章:

java - 动态打印表格行

java - 使用 Lucene SearchAfter 示例

java - ArrayList 包含方法无法正常工作?

速度 hasNext 方法

java - 如果值为 null 或空,如何使用 Apache Velocity 模板生成自关闭 XML 元素

android - 在 Android 上查找围绕圆圈的用户触摸事件的角度和速度

java - Velocity #foreach 与 XmlTool 节点列表与文本节点

java - 从字符串中解析带时区的日期

java - 创建抽象类的实例

java - 速度加/减速度