[英]Velocity 2.0: NoClassDefFoundError: org/apache/velocity/runtime/log/CommonsLogLogChute
在使用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
所有依賴都已滿足。 我們正在使用
在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上提示,但不確定發生了什么。
當overrideLogging為true時,Spring仍然需要類org.apache.velocity.runtime.log.CommonsLogLogChute,而它在Velocity 2.0中已經消失,因為Velocity現在使用slf4j日志框架。
如果需要overrideLogging為true,則需要等待Spring Velocity類的更新。
Velocity改變了日志記錄:
除非在配置中使用runtime.log.name指定,否則使Velocity使用基本記錄程序命名空間'org.apache.velocity',並使用此基本命名空間使用運行時實例日志,並使用子命名空間記錄其他模塊
CommonsLogLogChute在主要版本速度1.7之前添加:
添加CommonsLogLogChute,允許通過commons-logging進行日志記錄。
因此,您可能在運行時環境中有一個舊的jar或配置。
阿里巴巴為該案例實施了支持上下文包: 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。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.