Velocity 2.0:NoClassDefFoundError:org/apache/velocity/runtime/log/CommonsLogLogChute

gen*_* b. 8 java spring velocity

在使用 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
Run Code Online (Sandbox Code Playgroud)

所有依赖关系均已得到满足。我们正在使用

  • 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"/>
Run Code Online (Sandbox Code Playgroud)

对此有什么想法吗?

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

defaults, directive, parser, resource, visitor
Run Code Online (Sandbox Code Playgroud)

但不是log

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

<bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFactoryBean"> 
    <property name="overrideLogging" value="false" />
</bean>
Run Code Online (Sandbox Code Playgroud)

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

Cla*_*son 7

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

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

2022 年 6 月 21 日编辑- 从 2.3 版本开始,Velocity 确实提供了Spring 支持