8

Multiple annotations found at this line: - Class 'org.springframework.ui.velocity.VelocityEngineFactoryBean' not found - Class 'org.springframework.ui.velocity.VelocityEngineFactoryBean' not found [config set: MyApp/web- context]

    <bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFactoryBean">
  <property name="velocityProperties">
     <value>
      resource.loader=class
      class.resource.loader.class=org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
     </value>
  </property>
</bean>
Srinu Babu
  • 422
  • 2
  • 5
  • 16

4 Answers4

7

Spring has marked Velocity package org.springframework.ui.velocity as deprecated in Spring 4.3 and removed it completely in Spring 5.0.1 (according to Jürgen Höller, it's because Velocity Framework "dates back to 2010").
Source: https://jira.spring.io/browse/SPR-13795.

However, you can still use Velocity 1.7 in Spring 5.0.x Framework.
Just follow the answer of @bekce in this thread.

Itzik Shachar
  • 744
  • 5
  • 16
5

As it was mentioned on VelocityEngineUtils has been removed in Spring 3.2 so what else to use? you need to have Velocity dependency:

<dependency>
    <groupId>org.apache.velocity</groupId>
    <artifactId>velocity</artifactId>
    <version>1.7</version>
</dependency>

For XML configs, replace deprecated VelocityEngineFactoryBean with VelocityEngine:

<util:properties id="velocityProperties">
  <prop key="resource.loader">class</prop>
  <prop key="class.resource.loader.class">org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader</prop>
</util:properties>

<bean id="velocityEngine" class="org.apache.velocity.app.VelocityEngine">
  <constructor-arg ref="velocityProperties">
</bean>
Justinas Jakavonis
  • 8,220
  • 10
  • 69
  • 114
1

The VelocityEngineFactoryBean has been deprecated in Spring 5, and the option is to use spring-velocity-support package.

<dependency>
    <groupId>org.apache.velocity</groupId>
    <artifactId>spring-velocity-support</artifactId>
    <version>2.3</version>
</dependency>

The velocityEngine bean can be updated as

<bean id="velocityEngine"
    class="org.apache.velocity.spring.VelocityEngineFactoryBean">
    <property name="velocityProperties">
        <props>
            <prop key="resource.loader">class</prop>
            <prop key="class.resource.loader.class">
                org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
            </prop>
        </props>
    </property>
</bean>

https://github.com/apache/velocity-engine/tree/master/spring-velocity-support

eric.chenchao
  • 181
  • 1
  • 4
-1

if the code need VelocityEngineFactoryBean class, project must contains the dependency of spring-context-support and make sure spring-context-support version should below 5.0.0 because VelocityEngineFactoryBean & VelocityEngineUtils classes deprecated for the 5.0.0 and above versions.

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context-support</artifactId>
        <version>4.2.3.RELEASE</version>
    </dependency>
karthi_03
  • 309
  • 2
  • 4
  • Never mix jars from different version of a framework, that is only a path to weird errors and incompatible contracts. – M. Deinum May 31 '22 at 10:10