Using Spring to configure wro4j makes it easy to have different debug and cache settings based on the environment in which you run, as it moves the configuration from your web.xml to your Spring application.xml – which allows you to use the !PropertyPlaceholderConfigurer to obtain the desired runtime binding of configuration values.


A new implementation of ro.isdc.wro.http.WroFilter (called ro.isdc.wro.http.ConfigurableWroFilter) is available since 1.3.x version. It allows setting all of the properties you may need to configure.

Update web.xml

In order to configure it with spring, you have to use !DelegatingFilterProxy in the web.xml:


Your target bean name must match that which is configured in your application.xml below.

Configure applicationContext.xml

Now, you have to configure the bean, using property placeholders so that you can have different values for each environment that you run in:

<bean id="wroFilter" class="ro.isdc.wro.http.ConfigurableWroFilter">
  <property name="debug" value="${application.wrofilter.debug}"/>
  <property name="cacheUpdatePeriod" value="${application.wrofilter.cache-update-period}"/>
  <property name="modelUpdatePeriod" value="${application.wrofilter.model-update-period}"/>

Starting with 1.3.7 release, it is possible to externalize all wro4j configuration properties to a properties file. This is considered a preferred method. Specifying each property one by one is deprecated and will be removed in next major release (1.4.0). Now, instead of specifying each property one by one, it is enough to configure the !ConfigurableWroFilter this way:

<bean id="wroFilter" class="ro.isdc.wro.http.ConfigurableWroFilter">
  <property name="properties" ref="wroProperties"/>

<bean id="wroProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">  
    <property name="location" value="" />  

The is a resource file which holds all configurations. It can look like this:

#If true, it is DEVELOPMENT mode, by default this value is true
# Default is true
# MBean name to be used if JMX is enabled
# Default is 0
# Default is 0
# Default is false.
# Default is UTF-8

If any of these properties are not specified, the default value will be used.