Velocity 1.7-有时Directive.postRender在Velocity.evaluate中抛出NullPointerException

在使用Velocity模板时遇到了一个问题。对于模板中使用的foreach函数,它为NullPointerException抛出了Directive.postRender

奇怪的行为是,使用完全相同的模板和相同的输入数据,Velocity能够成功完成评估过程。 失败说100分之一。

任何人都可以分享见解吗?预先感谢!

版本:速度1.7

java.lang.NullPointerException: null
    at org.apache.velocity.runtime.directive.Directive.postRender(Directive.java:202) ~[velocity-1.7.jar:1.7]
    at org.apache.velocity.runtime.directive.Foreach.clean(Foreach.java:489) ~[velocity-1.7.jar:1.7]
    at org.apache.velocity.runtime.directive.Foreach.render(Foreach.java:443) ~[velocity-1.7.jar:1.7]
    at org.apache.velocity.runtime.parser.node.ASTDirective.render(ASTDirective.java:207) ~[velocity-1.7.jar:1.7]
    at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:342) ~[velocity-1.7.jar:1.7]
    at org.apache.velocity.runtime.RuntimeInstance.render(RuntimeInstance.java:1378) ~[velocity-1.7.jar:1.7]
    at org.apache.velocity.runtime.RuntimeInstance.evaluate(RuntimeInstance.java:1314) ~[velocity-1.7.jar:1.7]
    at org.apache.velocity.app.Velocity.evaluate(Velocity.java:254) ~[velocity-1.7.jar:1.7]

sts215 回答:Velocity 1.7-有时Directive.postRender在Velocity.evaluate中抛出NullPointerException

通过使用Velocity.init()更改代码来进行修复 到

VelocityEngine vc = new VelocityEngine();
vc.init();

第一个是单例实现,Velocity可能会在高度多线程的模式下丢失某些数据。通过将其更改为在每个pdf生成调用中使用新的实例,它就像一种魅力。

谢谢!

本文链接:https://www.f2er.com/3162634.html

大家都在问