spring - 如何正确设置速度的加载器路径

我希望我的速度引擎从设计的路径中查找模板。 我这样做了:

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

但仍在类文件夹中寻找模板。 有什么想法吗?

最佳答案

如春 documentation 所示,您可以尝试以下方法:

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

或者,您可以在 velocity.properties 中声明这些属性并指定

<bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFactoryBean">
  <property name="configLocation" value="/WEB-INF/velocity.properties"/>
</bean>

https://stackoverflow.com/questions/5342704/

相关文章:

java - Spring jsp页面未评估

java - 关于 Spring web.xml

java - 非法状态异常 : Cannot find changelog location: cl

java - Spring批处理远程分块和远程分区之间的区别

json - Spring 3.2RC1 中来自 JodaTime 的 jackson2 JSON

java - 在 Spring 注解中使用静态变量

java - 多语言数据库,默认回退

java - 我应该把我的 ThreadLocals 放在一个 Spring 注入(inject)的

java - cvc-complex-type.2.4.c : The matching wildc

java - 依赖注入(inject) servlet 监听器