将平台升至 Spring 5.3.9+velocity2.3+velocity-tools3.1

在 Spring 5.3.9下升级 Velocity 1.7.x 至 velocity2.3 + velocity-tools3.1 出现的问题,记录中...

spring-webmvc-4.3.9.RELEASE.jar 中 org/springframework/web/servlet/view/velocity 下
VelocityConfig.java
VelocityConfigurer.java
VelocityLayoutView.java
VelocityLayoutViewResolver.java
VelocityToolboxView.java
VelocityView.java
VelocityViewResolver.java
spring.vm
和 spring-context-support-4.3.9.RELEASE.jar中 org/springframework/ui/velocity下
SpringResourceLoader.java
VelocityEngineFactory.java

修改部分源码 其中VelocityToolboxView.java类中 第40行,

protected Context createVelocityContext(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response)
    throws Exception
  {
    ChainedContext velocityContext = new ChainedContext(new VelocityContext(model), getVelocityEngine(), request, response, getServletContext());
    if (getToolboxConfigLocation() != null)
    {
      ToolboxManager toolboxManager = ServletToolboxManager.getInstance(
        getServletContext(), getToolboxConfigLocation());
      Map<String, Object> toolboxContext = toolboxManager.getToolbox(velocityContext);
      //将Map<?, ?>替换成了Map<String, Object>,避免类型转换错误
      velocityContext.setToolbox(toolboxContext);
    }
    return velocityContext;
  }

问题1:commons-digester-2.x 升级至 commons-digester3.x

代码改变

Velocity 1.x -> ViewToolInfo toolinfo = (ViewToolInfo) digester.peek();

Velocity 2.x -> ViewToolInfo toolinfo = (ViewToolInfo) getDigester().peek();

问题2:Apache Commons Lang 2.x 替换为 Apache Commons Lang 3.x

问题3:commons-collections-3.x 替换为 commons-collections-4.x

问题4:$velocityCount失效 替换为 $foreach.count

问题5:configuration key 'resource.loader' has been deprecated in favor of 'resource.loaders'

posted @ 2021-12-13 14:47  锐洋智能  阅读(1460)  评论(1编辑  收藏  举报