如何使用带有速度模板的 Spring ResourceUrlEncodingFilter

How to use Spring ResourceUrlEncodingFilter with velocity template

Spring boot docs 建议速度模板支持 ResourceUrlEncodingFilter 以使用版本控制重写静态资产 url。引自文档:

Links to resources are rewritten at runtime in template, thanks to a ResourceUrlEncodingFilter, auto-configured for Thymeleaf, Velocity and FreeMarker.

我从 this blog 中找到了用于 url 重写的 thymeleaf 的语法。但是在花费了几个小时的 google 搜索之后,我无法找到 Velocity 模板语言的语法或宏。任何人都可以给我指出解释这一点的资源。

这是一个错误,请参阅 SPR-14027。 同时,您可以像这样定义自己的宏:

#macro( springResourceUrl $relativeUrl )$springMacroRequestContext.getContextUrl(${relativeUrl})#end

并这样称呼它:

<script src="#springResourceUrl("/script.js")"></script>

请注意,从 Spring 4.3 开始,Velocity 支持已弃用(参见 SPR-13235) and should be removed in Spring 5.0 (see SPR-13795)。