【问题标题】:Configure Velocity to read template file outside of the classpath配置 Velocity 以读取类路径之外的模板文件
【发布时间】:2012-09-30 00:32:16
【问题描述】:

我正在尝试将 Velocity 配置为从文件系统读取模板文件,而不是从类路径读取模板文件。如果我将velocityEngine配置为:

,我可以让它从类路径中读取模板文件:
<bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFactoryBean" 
          p:resourceLoaderPath="classpath:/com/myapp/test" 
          p:preferFileSystemAccess="false"/>  

并将 templatefile.vm 放入 com.myapp.test 包中。

如何更改上述内容,以便我可以将模板文件放在文件系统中的任何位置并访问它。我试过了,但没有用。

<bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFactoryBean" 
          p:resourceLoaderPath="c:\home\users\me\app\templates" 
          p:preferFileSystemAccess="true"/> 

我尝试用谷歌搜索是否可以找到解决方案,但大多数示例都是针对 Spring MVC 配置的。我正在使用独立的 Spring 应用程序。

谢谢

【问题讨论】:

    标签: java spring templates velocity


    【解决方案1】:

    尝试像这样使用file: 指定文件名:

    <bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFactoryBean" 
              p:resourceLoaderPath="file://c:\home\users\me\app\templates" 
              p:preferFileSystemAccess="true"/> 
    

    这就是我认为它应该起作用的原因。根据this document,当您将PreferFileSystemAccess 设置为true 时,它开始使用SpringResourceLoaderSpringResourceLoader 用途很广,这里有一个nice overview


    this 也可能是相关的。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-12-07
    • 1970-01-01
    • 2018-10-12
    • 2012-01-26
    • 2017-07-07
    • 2011-04-19
    • 2014-04-23
    相关资源
    最近更新 更多