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!