How to use variables in static content path in spring-servlet.xml

Wednesday, November 4, 2015

I want to make my asset folder base dependent on version to prevent caching issues for my users. I'm currently using spring with a spring-servlet.xml to configure my static routes.



This is my current configuration



 <!-- 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" />


I would like to use something like this but I don't know how to configure this.



 <!-- 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" />


The version variable is defined in application.properties and I am successfully using it in my JSP files. But I cant seem to use it when registering my static routes. Please Advice.

0 comments:

Post a Comment