gene b.
gene b.

Reputation: 11994

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

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

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.

Upvotes: 8

Views: 9776

Answers (3)

Claude Brisson
Claude Brisson

Reputation: 4130

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.

Edit on June 21st, 2022 - Since version 2.3, Velocity does provide Spring support.

Upvotes: 7

Patrick
Patrick

Reputation: 35234

Alibaba implemented a support context package for that case: https://github.com/alibaba/spring-velocity-support

Just add to 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>

But beware that your project now uses Velocity 2.0.

Upvotes: 0

Ori Marko
Ori Marko

Reputation: 58782

Velocity made a change in logging:

Make Velocity use the base logger namespace 'org.apache.velocity' unless specified with runtime.log.name in the configuration, and have the runtime instance log with this base namespace, and other modules log with children namespaces

CommonsLogLogChute added in before major version velocity 1.7:

Add a CommonsLogLogChute that allows logging through commons-logging.

So you probably have an old jar or configuration in your runtime environment.

Upvotes: 1

Related Questions