Use CDN Service in Spring MVC

A few days ago, I created TestZilla on Aliyun Elastic Compute Service.

However, with the increment of PV, I decided to use CDN to caches static files(images, css and javascripts).

But there's no one told me how to use CDN with Spring MVC, so I asked a question on StackOverflow.

Setup Spring Configuration

First of all, you need to use PropertyPlaceholderConfigurer in Spring Configuration(such as dispatcher-servlet.xml)

<!-- Property File Location -->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
	<property name="locations">
<util:properties id="propertyConfigurer" location="classpath:/"/>
<context:property-placeholder properties-ref="propertyConfigurer" />

Of course, you need to add XML Namespaces:

<beans xmlns=""

Create Properties File

As I was declared in the Spring Configuration, there's a in classpath.
You need to create the file and add following lines in it:


Of course, you can add extra properties if needed:


Use CDN Property in JSP

Now, we can get the URL of CDN in JSP as following:

<%@ taglib prefix="spring" uri="" %>
<spring:eval expression="@propertyConfigurer.getProperty('cdn.url')" var="cdnUrl" />
<!DOCTYPE html>
<html lang="${language}">
    <meta charset="UTF-8">
    <title>Home | TestZilla</title>
    <link rel="stylesheet" type="text/css" href="${cdnUrl}/css/semantic.min.css" />





Contact Us
  • Room 614, Zonghe Building, Harbin Institute of Technology
  • cshzxie [at]