How to set properly the loader path of velocity

╄→尐↘猪︶ㄣ 提交于 2019-12-30 01:56:06

问题


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?


回答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>



回答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>



回答3:


Try with Resource Loader as

org.apache.velocity.runtime.resource.loader.FileResourceLoader

Hope this helps.



来源:https://stackoverflow.com/questions/5342704/how-to-set-properly-the-loader-path-of-velocity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!