速度模板自动重新加载不起作用 [英] Velocity Template auto-reload doesn't work

查看:116
本文介绍了速度模板自动重新加载不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在更改速度模板后重新加载它.为此,我进行了以下设置,但是当我手动更改META-INF/template/内的.vm文件时,重新加载不起作用.

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

有什么主意吗?这是我的velocityEngine bean

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>

推荐答案

作为setResourceLoaderPath

请注意,无论如何都将启用资源缓存.使用文件资源加载器,将在访问时检查上次修改的时间戳以检测更改. 使用SpringResourceLoader,资源将被永久缓存(例如,用于类路径资源).

...

要强制使用SpringResourceLoader,即在任何情况下都不将路径解析为文件系统资源,请关闭"preferFileSystemAccess"标志.有关详细信息,请参见后者的javadoc.

To enforce the use of SpringResourceLoader, i.e. to not resolve a path as file system resource in any case, turn off the "preferFileSystemAccess" flag. See the latter's javadoc for details.

然后setPreferFileSystemAccess

设置是否更喜欢文件系统访问来进行模板加载. 通过文件系统访问,可以热检测模板更改.

如果启用此功能,VelocityEngineFactory将尝试将指定的"resourceLoaderPath"解析为文件系统资源(也将适用于扩展的类路径资源和ServletContext资源).

If this is enabled, VelocityEngineFactory will try to resolve the specified "resourceLoaderPath" as file system resource (which will work for expanded class path resources and ServletContext resources too).

默认为"true". 将其关闭以始终通过SpringResourceLoader加载(即,作为流,而没有热检测到模板更改),如果您的某些模板位于扩展的类目录中,而另一些模板位于jar文件中,则可能有必要.

Default is "true". Turn this off to always load via SpringResourceLoader (i.e. as stream, without hot detection of template changes), which might be necessary if some of your templates reside in an expanded classes directory while others reside in jar files.

因此,似乎有一些因素导致了该问题.将SpringResourceLoaderclasspath:伪协议结合使用会使Spring无限地缓存模板.最重要的是,禁用了preferFileSystemAccess,以确保模板永远不会通过文件系统进行访问.

So looks like there are a few things that contribute to the problem. Using SpringResourceLoader with classpath: pseudo-protocol makes Spring cache the template infinitely. On top of that preferFileSystemAccess is disabled which makes sure that template is never accessed through the file system.

这篇关于速度模板自动重新加载不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆