我想使我的資產文件夾基礎依賴於版本,以防止爲我的用戶緩存問題。我目前使用spring和servlet.xml來配置我的靜態路由。如何在spring-servlet.xml中的靜態內容路徑中使用變量
這是我目前的配置
<!-- Static routes -->
<mvc:resources mapping="/assets/**" location="/assets/" cache-period="0" />
<mvc:resources mapping="/img/**" location="/assets/img/" cache-period="31556926" />
<mvc:resources location="/assets/img/favicon.ico" mapping="/favicon.ico" />
我想用這樣的事情,但我不知道如何配置這一點。
<!-- Static routes -->
<mvc:resources mapping="/assets/${version}/**" location="/assets/" cache-period="0" />
<mvc:resources mapping="/img/**" location="/assets/${version}/img/" cache-period="31556926" />
<mvc:resources location="/assets/${version}/img/favicon.ico" mapping="/favicon.ico" />
version變量在application.properties中定義,我成功地在我的JSP文件中使用它。但我註冊我的靜態路由似乎不能使用它。請指教。
我認爲Spring MVC已經構建了資源緩存清除的功能。看看[這篇文章](http://stackoverflow.com/a/30139512/1291150)或[這一個](https://spring.io/blog/2014/07/24/spring-framework-4 -1-handling-static-web-resources),然後嘗試實現一些自定義解決方案。免責聲明:我沒有親自嘗試過,但它可以幫助你。 [This SO post](http://stackoverflow.com/a/9204940/1291150)如果您決定使用自定義解決方案,則包含對您的問題的解答(mvc:resources中的佔位符)。祝你好運! –
謝謝,聽起來不錯。雖然我可能仍然使用自定義解決方案來運行,但是如果我能夠按照版本提供的應用程序的想法工作,那麼我可以運行它。 –