Issue
On starting up my Web app with Velocity 2.0 I'm getting the following error:
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
All dependencies have been satisfied. We are using
- 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 (yes we do have Commons-Logging)
In applicationContext.xml the velocityEngine bean is defined as follows
<bean id="velocityEngine"
class="org.springframework.ui.velocity.VelocityEngineFactoryBean"/>
Any thoughts on this?
My file velocity-engine-core-2.0.jar
only contains the following .runtime
subpackages:
defaults, directive, parser, resource, visitor
but no log
.
UPDATE The following overrideLogging = FALSE in the Spring Velocity Engine bean declaration solved the problem. But why?
<bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFactoryBean">
<property name="overrideLogging" value="false" />
</bean>
I just followed a tip on https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/ui/velocity/VelocityEngineFactory.html but not sure what happened.
Solution
When overrideLogging is true, the class org.apache.velocity.runtime.log.CommonsLogLogChute is still required by Spring while it has disappeared in Velocity 2.0, since Velocity now uses the slf4j logging framework.
You'll need to wait for an update of the Spring Velocity classes if you need overrideLogging to be true.
Answered By - Claude Brisson
Answer Checked By - Robin (JavaFixing Admin)