【问题标题】:Velocity 2.0: NoClassDefFoundError: org/apache/velocity/runtime/log/CommonsLogLogChute速度 2.0:NoClassDefFoundError:org/apache/velocity/runtime/log/CommonsLogLogChute
【发布时间】:2018-02-17 12:03:58
【问题描述】:

在使用 Velocity 2.0 启动我的 Web 应用程序时,我收到以下错误:

Caused by: java.lang.NoClassDefFoundError: 
             org/apache/velocity/runtime/log/CommonsLogLogChute
    at org.springframework.ui.velocity.VelocityEngineFactory.createVelocityEngine(VelocityEngineFactory.java:240)
    at org.springframework.ui.velocity.VelocityEngineFactoryBean.afterPropertiesSet(VelocityEngineFactoryBean.java:60)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624)
    ... 34 more

所有依赖项都已满足。我们正在使用

  • slf4j-api-1.7.25.jar
  • slf4j-simple-1.7.25.jar
  • commons-lang3-3.5.jar
  • commons-io-2.5.jar
  • commons-logging-1.2.jar(是的,我们有 Commons-Logging)

在 applicationContext.xml 中,velocityEngine bean 定义如下

<bean id="velocityEngine" 
class="org.springframework.ui.velocity.VelocityEngineFactoryBean"/>

对此有什么想法吗?

我的文件velocity-engine-core-2.0.jar 仅包含以下.runtime 子包:

defaults, directive, parser, resource, visitor

但没有log

更新 Spring Velocity Engine bean 声明中的以下 overrideLogging = FALSE 解决了该问题。 但是为什么?

<bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFactoryBean"> 
    <property name="overrideLogging" value="false" />
</bean>

我只是按照提示 https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/ui/velocity/VelocityEngineFactory.html 但不确定发生了什么。

【问题讨论】:

    标签: java spring velocity


    【解决方案1】:

    Velocity 改变了日志记录:

    使 Velocity 使用基本记录器命名空间 'org.apache.velocity' 除非在配置中使用 runtime.log.name 指定,并且有 具有此基本命名空间和其他模块的运行时实例日志 使用子命名空间记录

    在velocity 1.7主要版本之前添加了CommonsLogLogChute:

    添加一个允许通过 commons-logging 进行日志记录的 CommonsLogLogChute。

    所以你的运行时环境中可能有一个旧的 jar 或配置。

    【讨论】:

      【解决方案2】:

      当 overrideLogging 为 true 时,Spring 仍然需要类 org.apache.velocity.runtime.log.CommonsLogLogChute 而它在 Velocity 2.0 中消失了,因为 Velocity 现在使用 slf4j 日志框架。

      如果您需要将 overrideLogging 设置为 true,则需要等待 Spring Velocity 类的更新。

      【讨论】:

      • 谢谢,但不会有新的 SpringVelocity——它现在已被弃用:Spring 说:“从 Spring Framework 4.3 开始,由于六年没有对阿帕奇速度项目。我们推荐 Spring 的 FreeMarker 支持,或者 Spring 支持本身附带的 Thymeleaf。"
      • 此评论是在 Velocity 2.0 发布之前发表的。因此,迟早会有人为 2.0 贡献一个 Spring Velocity 支持包(我认为这不会太难),如果 Spring 不想的话,它可以托管在 Velocity 站点上。
      【解决方案3】:

      阿里巴巴针对该案例实施了支持上下文包:https://github.com/alibaba/spring-velocity-support

      只需添加到 maven:

      <!-- Spring Framework -->
      <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-context-support</artifactId>
          <version>${spring.framework.version}</version>
      </dependency>
      
      <!-- Spring Context Velocity -->
      <dependency>
          <groupId>com.alibaba.spring</groupId>
          <artifactId>spring-context-velocity</artifactId>
          <version>1.4.3.18.RELEASE</version>
      </dependency>
      

      但请注意,您的项目现在使用 Velocity 2.0。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-10-28
        • 2018-03-13
        • 1970-01-01
        • 2013-03-25
        • 2018-05-08
        • 2018-09-13
        • 2014-07-02
        • 1970-01-01
        相关资源
        最近更新 更多