Velocitytool has a problem with the tool of Velocity.

Source: Internet
Author: User

Velocitytool has a problem with the tool of Velocity.

SpringMVC + Velocity architecture is used for development. Velocity tools must be used. The following code is used in the integration era:

<Bean id = "viewResolver"
Class = "org. springframework. web. servlet. view. velocity. VelocityViewResolver">
<Property name = "cache" value = "true"/>
<Property name = "suffix" value = ". vm"/>
<Property name = "contentType">
<Value> text/html; charset = UTF-8 </value>
</Property>
<Property name = "requestContextAttribute" value = "rc"/>
<Property name = "toolboxConfigLocation" value = "velocity-toolbox.xml"/>
<! -- Define velocity DATE format -->
<Property name = "datatelattribute">
<Value> dateTool </value>
</Property>

</Bean>

This volocity-toolbox.xml configuration file is placed under src, that is, after the war package is packaged in the WEB-INF/classes directory, but always reported the following error:

Caused by: java. lang. NullPointerException
At org. springframework. web. servlet. view. velocity. VelocityToolboxView. createVelocityContext (VelocityToolboxView. java: 111)
At org. springframework. web. servlet. view. velocity. VelocityView. renderMergedTemplateModel (VelocityView. java: 287)
At org. springframework. web. servlet. view. AbstractTemplateView. renderMergedOutputModel (AbstractTemplateView. java: 167)
At org. springframework. web. servlet. view. AbstractView. render (AbstractView. java: 264)
At org. springframework. web. servlet. DispatcherServlet. render (DispatcherServlet. java: 1208)
At org. springframework. web. servlet. DispatcherServlet. processDispatchResult (DispatcherServlet. java: 992)
At org. springframework. web. servlet. DispatcherServlet. doDispatch (DispatcherServlet. java: 939)
At org. springframework. web. servlet. DispatcherServlet. doService (DispatcherServlet. java: 856)
At org. springframework. web. servlet. FrameworkServlet. processRequest (FrameworkServlet. java: 953)
... 23 more

No information was found on the Internet, so I debugged the source code and found it in the org class. apache. velocity. tools. view. servlet. use servletContext to read this file in ServletToolboxManager. getResourceAsStream is read by the API. This makes it clear that it was read by the class loader. For details about how to use servletContext. getResourceAsStream, refer to other materials. However, when I looked back at other people's configuration documents, I found that they used the relative path of the project when configuring the file path, so I changed this path: /WEB-INF/classes/velocity-toolbox.xml, problem solving!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.