Velocity 模板自动重新加载不起作用
我想在速度模板发生变化时重新加载它。为此,我设置了以下内容,但是当我手动更改 META-INF/template/
内的 .vm 文件时,重新加载不起作用。
velocimacro.library.autoreload = true
[spring|file|class].resource.loader.cache = false
有什么想法吗?这是我的velocityEngine bean
<bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFactoryBean">
<property name="resourceLoaderPath" value="classpath:META-INF/template/" />
<property name="preferFileSystemAccess" value="false" />
<property name="velocityProperties">
<props>
<prop key="spring.resource.loader.cache">false</prop>
<prop key="file.resource.loader.cache">false</prop>
<prop key="class.resource.loader.cache">false</prop>
<prop key="velocimacro.library.autoreload">true</prop>
<prop key="resource.loader">spring</prop>
<prop key="directive.foreach.counter.name">counter</prop>
<prop key="directive.foreach.counter.initial.value">0</prop>
<prop key="spring.resource.loader.class">
org.springframework.ui.velocity.SpringResourceLoader
</prop>
</props>
</property>
</bean>
I want to reload velocity template as it's changed. For this I've set the followings, but reload doesn't work when I manually change a .vm file inside META-INF/template/
.
velocimacro.library.autoreload = true
[spring|file|class].resource.loader.cache = false
Any idea? Here is my velocityEngine bean
<bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFactoryBean">
<property name="resourceLoaderPath" value="classpath:META-INF/template/" />
<property name="preferFileSystemAccess" value="false" />
<property name="velocityProperties">
<props>
<prop key="spring.resource.loader.cache">false</prop>
<prop key="file.resource.loader.cache">false</prop>
<prop key="class.resource.loader.cache">false</prop>
<prop key="velocimacro.library.autoreload">true</prop>
<prop key="resource.loader">spring</prop>
<prop key="directive.foreach.counter.name">counter</prop>
<prop key="directive.foreach.counter.initial.value">0</prop>
<prop key="spring.resource.loader.class">
org.springframework.ui.velocity.SpringResourceLoader
</prop>
</props>
</property>
</bean>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
作为
setResourceLoaderPath
doc 说:然后对于
setPreferFileSystemAccess
看来有一些因素导致了这个问题。使用
SpringResourceLoader
和classpath:
伪协议使得 Spring 无限缓存模板。最重要的是,preferFileSystemAccess
被禁用,这确保模板永远不会通过文件系统访问。As
setResourceLoaderPath
doc says:Then for
setPreferFileSystemAccess
So looks like there are a few things that contribute to the problem. Using
SpringResourceLoader
withclasspath:
pseudo-protocol makes Spring cache the template infinitely. On top of thatpreferFileSystemAccess
is disabled which makes sure that template is never accessed through the file system.添加此属性为我解决了这个问题:
使用下面的属性时我遇到了同样的问题,但添加上面的属性使我能够自动重新加载工作:
请参阅 如何在不重新启动速度的情况下编辑 velocimacro?
Adding this property resolved this issue for me:
I had the same problem when using the properties below but adding the above property enabled me to get auto-reload to work:
Please see How to edit a velocimacro without restarting velocity?
好的,我的velocityEngine bean设置如下:(
假设你使用Spring框架,顺便说一句)
我对缓存没有任何问题。但我使用配置器 bean 而不是 beanfactory。尝试看看这个。
还有一件事,这很琐碎,但仍然......,修改模板后你真的重新部署你的项目吗?
Ok, i have velocityEngine bean set like this:
(Assuming you use Spring framework, by the way)
and I have no problems with caching whatsoever. But I use the configurer bean instead of beanfactory. Try look into this.
And there's the thing, it's trivial, but still..., do you actually redeploy your project after modifying the template?
我过去也遇到过同样的问题,所以我写了这篇博客文章: Spring-mvc + Velocity + DCEVM
主要思想是至少在开发时使用它:
我发现它比 SpringResourceLoader 效果更好,因为现在在我的模板中我可以包含如下内容:
标头的路径位于 /WEB-INF/views/header.vm 中
I had the same issue in the past, so I've written this blog entry: Spring-mvc + Velocity + DCEVM
The principal idea is to use this at least at development time:
I've found that it works better than the SpringResourceLoader because now in my templates I can have includes like these:
Where the path of the header is in /WEB-INF/views/header.vm