How to set properly the loader path of velocity
35,978
Solution 1
As illustrated in the spring documentation, you could try the following:
<bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFactoryBean">
<property name="velocityProperties">
<props>
<prop key="resource.loader">file</prop>
<prop key="file.resource.loader.class">
org.apache.velocity.runtime.resource.loader.FileResourceLoader
</prop>
<prop key="file.resource.loader.path">${webapp.root}/WEB-INF/velocity</prop>
<prop key="file.resource.loader.cache">false</prop>
</props>
</property>
</bean>
Alternately, you could declare these properties in a velocity.properties
and specify that
<bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFactoryBean">
<property name="configLocation" value="/WEB-INF/velocity.properties"/>
</bean>
Solution 2
Try this:
<bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFactoryBean">
<property name="resourceLoaderPath" value="/email_templates/"/>
</bean>
<bean name="mailTest" class="com.crisil.web.MailTestController">
<property name="velocityEngine" ref="velocityEngine"/>
</bean>
![storm_buster](https://i.stack.imgur.com/Dj4ip.jpg?s=256&g=1)
Author by
storm_buster
Software technology interests: java, react, kafka, aws https://www.buymeacoffee.com/stunaz You can contact me anytime! Only in a professional way, though.
Updated on June 05, 2020Comments
-
storm_buster about 4 years
i would like that my velocityengine look for templates from a designed path. i did this :
<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 class.resource.loader.resourceLoaderPath=/mytemplates </value> </property>
but is still looking for templates in the classes folder. any idea?