在实例化 Velocity 时出现此错误(仅发布“由”引起的消息):
java.lang.RuntimeException: Velocity could not be initialized!
Caused by: org.apache.velocity.exception.VelocityException: Error initializing log: Failed to initialize an instance of org.apache.velocity.runtime.log.Log4JLogChute with the current runtime configuration.
Caused by: org.apache.velocity.exception.VelocityException: Failed to initialize an instance of org.apache.velocity.runtime.log.Log4JLogChute with the current runtime configuration.
Caused by: java.lang.RuntimeException: Error configuring Log4JLogChute :
Caused by: java.io.FileNotFoundException: velocity.log (Permission denied)
这是我的代码片段:
VelocityEngine ve = new VelocityEngine();
ve.evaluate(context, writer, "org.apache.velocity.runtime.log.NullLogChute", this.templateString);
起初我的代码是这样的:
runtimeServices = RuntimeSingleton.getRuntimeServices();
node = runtimeServices.parse(reader, templateName);
在我的 Windows 机器上它工作正常,但在 Linux 系统 (ubuntu 10.04) 上它不工作。这post对我帮助不大,因为我还没有找到任何线索,我必须向哪个目录授予写权限。
我发现,以下代码也适用于 Linux 机器:
String logPath = request.getRealPath("/velocity.log");
RuntimeSingleton.setProperty( RuntimeConstants.RUNTIME_LOG, logPath );
runtimeServices = RuntimeSingleton.getRuntimeServices();
node = runtimeServices.parse(reader, templateName);
这不是一个很好的解决方案,因为我永远无法确定我是否对我的真实上下文路径具有写权限。最好的办法是,只关闭 Velocity 的日志记录。
我必须设置哪些不同的日志记录配置? NullLogChute
只是没有工作还是我使用它不合适?
提前致谢!
最佳答案
您好,问题出在受写入权限保护的文件系统上。 实际上在你的堆栈跟踪中你有:
java.io.FileNotFoundException: velocity.log (Permission denied)
所以决定将速度日志写入何处是件好事。 你说好话,你不知道在生产中你是否可以写到一个特定的路径。 所以最好将该路径放在系统管理员可以根据需要修改的属性文件中。
如果对您有帮助,请查看我对另一篇文章的回答。
链接 here
关于linux - 在 Linux 系统上记录速度错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7793002/