0

我正在尝试将 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 应用程序。

谢谢

4

1 回答 1

2

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

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

这就是我认为它应该起作用的原因。根据此文档,当您设置PreferFileSystemAccesstrue它开始使用SpringResourceLoader. SpringResourceLoader用途广泛,这里有一个很好的概述


也可能是相关的。

于 2012-09-30T00:35:26.013 回答