Apache Velocity - 由于 slf4j 依赖性,无法评估脚本
Apache Velocity - Failed to eval script due to slf4j dependencies
继续 问题我无法在 velocity 2.0 中执行脚本,
我使用 jars: velocity-engine-scripting-2.0.jar, velocity-engine-scripting-2.0.jar, commons-collections-3.2.2.jar
我正在尝试遵循 developer guide 示例:
ScriptEngineManager manager = new ScriptEngineManager();
manager.registerEngineName("velocity", new VelocityScriptEngineFactory());
ScriptEngine engine = manager.getEngineByName("velocity");
System.setProperty(VelocityScriptEngine.VELOCITY_PROPERTIES, "path/to/velocity.properties");
String script = "Hello $world";
Writer writer = new StringWriter();
engine.getContext().setWriter(writer);
Object result = engine.eval(script);
System.out.println(writer);
初始化时出现 slf4j
错误,我正在使用 slf4j-jdk14.jar。即使在添加 slf4j-api-1.8.0-alpha2.jar
之后,我也没有找到针对此特定错误的解决方案
class org.apache.velocity.script.VelocityScriptEngine
java.lang.NoSuchMethodError: org.slf4j.Logger.trace(Ljava/lang/String;)V
at org.apache.velocity.runtime.RuntimeInstance.init(RuntimeInstance.java:233)
at org.apache.velocity.script.VelocityScriptEngine.initVelocityEngine(VelocityScriptEngine.java:212)
at org.apache.velocity.script.VelocityScriptEngine.compile(VelocityScriptEngine.java:299)
at org.apache.velocity.script.VelocityScriptEngine.compile(VelocityScriptEngine.java:288)
- 请注意,我 在我的 class 中没有使用任何日志记录 ,所以我不需要任何迁移到
slf4j
.
编辑 1:
我在 slf4j FAQ 中发现了关于 Velocity 的有趣评论:
The logging strategy adopted by the Velocity project is a good example
of the "custom logging abstraction" anti-pattern. By adopting an
independent logging abstraction strategy, Velocity developers have
made life harder for themselves, but more importantly, they made life
harder for their users.
编辑 2:
Velocity dependencies 在运行时是:slf4j-api 1.7.25 和 commons-lang 3.5 我添加到 classpath 但仍然有同样的错误
您在常见问题解答中找到的文档摘录显然已过时。
dependencies 页面明确指出,虽然在编译和运行时需要 slf4j-api,但您还需要选择一个 slf4j 绑定,例如 slf4j-simple,它将记录到默认为标准错误。
继续
我使用 jars: velocity-engine-scripting-2.0.jar, velocity-engine-scripting-2.0.jar, commons-collections-3.2.2.jar
我正在尝试遵循 developer guide 示例:
ScriptEngineManager manager = new ScriptEngineManager();
manager.registerEngineName("velocity", new VelocityScriptEngineFactory());
ScriptEngine engine = manager.getEngineByName("velocity");
System.setProperty(VelocityScriptEngine.VELOCITY_PROPERTIES, "path/to/velocity.properties");
String script = "Hello $world";
Writer writer = new StringWriter();
engine.getContext().setWriter(writer);
Object result = engine.eval(script);
System.out.println(writer);
初始化时出现 slf4j
错误,我正在使用 slf4j-jdk14.jar。即使在添加 slf4j-api-1.8.0-alpha2.jar
class org.apache.velocity.script.VelocityScriptEngine
java.lang.NoSuchMethodError: org.slf4j.Logger.trace(Ljava/lang/String;)V
at org.apache.velocity.runtime.RuntimeInstance.init(RuntimeInstance.java:233)
at org.apache.velocity.script.VelocityScriptEngine.initVelocityEngine(VelocityScriptEngine.java:212)
at org.apache.velocity.script.VelocityScriptEngine.compile(VelocityScriptEngine.java:299)
at org.apache.velocity.script.VelocityScriptEngine.compile(VelocityScriptEngine.java:288)
- 请注意,我 在我的 class 中没有使用任何日志记录 ,所以我不需要任何迁移到
slf4j
.
编辑 1:
我在 slf4j FAQ 中发现了关于 Velocity 的有趣评论:
The logging strategy adopted by the Velocity project is a good example of the "custom logging abstraction" anti-pattern. By adopting an independent logging abstraction strategy, Velocity developers have made life harder for themselves, but more importantly, they made life harder for their users.
编辑 2:
Velocity dependencies 在运行时是:slf4j-api 1.7.25 和 commons-lang 3.5 我添加到 classpath 但仍然有同样的错误
您在常见问题解答中找到的文档摘录显然已过时。
dependencies 页面明确指出,虽然在编译和运行时需要 slf4j-api,但您还需要选择一个 slf4j 绑定,例如 slf4j-simple,它将记录到默认为标准错误。