How to set properly the loader path of velocity
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=cla开发者_开发知识库ss
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?
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>
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>
Try with Resource Loader as
org.apache.velocity.runtime.resource.loader.FileResourceLoader
Hope this helps.
精彩评论