速度 +春天
我正在尝试使用上述组件设置一个网络应用程序。除了最后一个障碍(集成 Spring 和 Spring)之外,我已经跨越了所有障碍。速度工具。我今天早上看到了这篇文章,并用答案与提供的略有不同。但是,一旦我尝试添加 ParameterTool 到我的模板之一,如下所示:
#foreach( $key in $params.keySet() )
$key = $params.getValue($key)
<br />
#end
我收到 NPE java.lang.UnsupportedOperationException:请求为 null。 ParameterTool 必须先初始化!根据我读到的内容,这意味着工具配置正确,只是它无权访问请求。注意:我也收到了已接受的解决方案的错误。
有人能够成功地将这些工具与 Spring 结合使用吗?似乎这是一个已知的缺陷,因为有一个 Open Jira 用于此 Open Jira SPR-5514
I am attempting to setup a webapp with the above components. I've jumped all but the last hurdle which is integrating Spring & Velocity Tools. I saw this post this morning, and updated it with a slightly different answer than what was provided. However, once I attempted to add in ParameterTool to one of my templates like so:
#foreach( $key in $params.keySet() )
$key = $params.getValue($key)
<br />
#end
I receive a NPE java.lang.UnsupportedOperationException: Request is null. ParameterTool must be initialized first! According to what I've read that means that the tooling was configured properly, just that it doesn't have access to the Request. Note: I receive the error with the accepted solution as well.
Has anyone successfully been able to use these tools with Spring? Seems that it's a known deficiency as there is an Open Jira for this Open Jira SPR-5514
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
接受的答案的稍微修改版本< 此问题中的 /a> 解决了此问题。
您需要返回 ViewToolContext,而不是返回 ViewContext。您还需要准备工具箱并根据需要在会话/请求上设置它们:
您将需要以您需要的方式初始化 toolContext (查看我提供的答案 此处了解如何使用更新的 API 执行此操作,因为您将需要访问ToolboxFactory。
修改后的 createVelocityContext 方法现在需要在创建 ViewToolContext 之前按以下方式准备工具箱:
A slightly modified version of The accepted answer from this question resolves this issue.
Instead of returning a ViewContext you need to return a ViewToolContext. You will also need to prepare the toolboxes and set them on the session / request as applicable:
You will need to initialize the toolContext in whichever manner you need (look at my provided answer here on how to do this with the updated APIs, as you're going to need access to the ToolboxFactory.
The modified createVelocityContext method will now need to prepare the toolboxes prior to creating the ViewToolContext in the following manner: