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

问题描述 投票:3回答:3

在使用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-火1.7.25.jar
  • SLF4J-简单1.7.25.jar
  • 公地lang3-3.5.jar
  • 公地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
3个回答
4
投票

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

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


1
投票

Velocity改变了日志记录:

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

CommonsLogLogChute在主要版本速度1.7之前添加:

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

因此,您可能在运行时环境中有一个旧的jar或配置。


0
投票

阿里巴巴为该案件实施了支持上下文包: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。

© www.soinside.com 2019 - 2024. All rights reserved.