如何在 Spring MVC 中禁用 freemarker 缓存
我正在使用 spring mvc v3 和 freemarker 视图,并且无法禁用缓存。 我尝试在(spring-servlet.xml)中的 viewResolver 元素中将缓存设置为 false,但没有成功。
基本上我想在 freemarker 中进行一些更改,并仅通过刷新在浏览器中查看这些更改(无需重新启动应用程序)
有任何提示如何执行此操作吗?
I'm using spring mvc v3 with freemarker views and cannot disable caching.
I tried by setting cache to false in viewResolver element in (spring-servlet.xml) but didn't work.
Basically what I'd like to the do some changes in freemarker and see these changes in the browser with refresh only (w/o restarting the application)
Any hints how to do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
在我的 XML 中,以下内容是成功的:
这是我的邮件配置,但 freemarkerConfig 也应该对您感兴趣。
In my XML the following was successful:
This is my mail config, but the freemarkerConfig should be interesting four you, too.
我不使用 xml 配置来配置 freemarker,而是使用
@Configuration
带注释的类;因为我更喜欢 Spring-Boot' 风格。因此,您可以像这样禁用 freemarker 的缓存:关键在于:
但您也可以使用此说明:
它应该适合您。
I dont use to configure freemarker with xml configurations but with
@Configuration
annotated classes; cause i rather the Spring-Boot´ style. So you can disable the freemarker´s cache like this:The key is in:
But you can also use this instruction instead:
It should work for you.
在应用程序属性中:
In application.properties:
根据 手册 的定义:
。 html#setSetting%28java.lang.String,%20java.lang.String%29" rel="nofollow">freemarker.template.Configuration javadocs,位于 setSetting(key, value) 方法。
因此,简而言之,只需将配置 template_update_delay 设置为 0 即可立即检测更改。
As defined by the manual :
After searching around, the configuration key was in the freemarker.template.Configuration javadocs, at the setSetting(key, value) method.
So, in short, just set the config template_update_delay to 0 for immediate change detection.
您是否检查了 FreeMarker 文档,其中包含有关如何影响模板缓存的一些提示FreeMarker
配置
级别。我不确定您是否可以从 Spring MVC 内部访问 FreeMarkerConfiguration
对象,但如果可以,那么上面提到的文档页面可能会为您指出一个可能的解决方案。Did you check the FreeMarker documentation, which contains some hints regarding how to influence template caching at the FreeMarker
Configuration
level. I'm not sure if you have access to the FreeMarkerConfiguration
object from inside Spring MVC, but if you have, then the documentation page mentioned above could point you towards a possible solution.我浪费了最后两天的时间(完全注意这个项目)试图禁用缓存。事实证明,我在 context.xml 中设置了两个选项 antiJARLocking 和 antiResourceLocking。那么模板将始终被缓存
I wasted the last two days (note entirely for this project) trying to disable the cache. It turns out I have the two options antiJARLocking and antiResourceLocking set in my context.xml. Then the templates will ALWAYS be cached
我遇到了同样的问题,只能通过实现自定义模板加载器来解决。这是工作代码:
I had the same problem which I could solve only by implementing a custom template loader. Here is the working code:
看来在最近发布的 FreeMarker 2.3.17 版本中,出现了一种合法且更简单的方法:
freemarker.cache.NullCacheStorage
。It seems that in the recently released FreeMarker version 2.3.17, a legal and simpler way to do it has appeared:
freemarker.cache.NullCacheStorage
.