Reloading Tiles2 Config in Spring 3.x

Posted on September 21, 2011
Tags: Spring

When you are using Tiles for layout composition with Spring you configure it as a view resolver by adding something like this to the applicationContext.xml

    <!-- Configure the Tiles templates -->
    <bean id="tilesConfigurer"
        <property name="definitions">
        <property name="preparerFactoryClass"
            value="org.springframework.web.servlet.view.tiles2.SpringBeanPreparerFactory" />
    <!-- Resolve views using Tiles -->
    <bean id="tilesViewResolver"
        <property name="viewClass"
            value="org.springframework.web.servlet.view.tiles2.TilesView" />

This will read the tiles.xml on startup. If you want it to refresh when the file changes you either need to add the Tiles filter, or more elegantly just add this context-param to the web.xml

<context-param>   <param-name>org.apache.tiles.definition.dao.LocaleUrlDefinitionDAO.CHECK_REFRESH</param-name>  <param-value>true</param-value> </context-param> 

Even better for testing environments, you can also put the declaration in your context.xml file, so you can switch it on and off on a per-deployment basis

   <Parameter name="org.apache.tiles.definition.dao.LocaleUrlDefinitionDAO.CHECK_REFRESH"
        value="true" override="false" /></pre>