Load XML definition files using wildcards

XML definition files can be loaded using wildcard, but this behaviour is not the default, due to compatibility reasons to Tiles 2.0.x.


To use wildcards in XML definition files, you need to put the following libraries in your classpath:

  • spring-core.jar
  • spring-web.jar
  • spring-context.jar
  • spring-beans.jar
  • aopalliance.jar

    If you are using Maven, simply depend on spring-web package.


To be able to specify Tiles XML definition files using wildcards, there is the need to override the Tiles application context creation. For example, if you are using parameter-based initialization, provide a new value for the org.apache.tiles.context.AbstractTilesApplicationContextFactory init parameter. For example:



To load XML definition files using wilcards you can proceed, as usual, in two ways:

  • If you are using parameter-based initialization, provide a new value for the org.apache.tiles.definition.DefinitionsFactory.DEFINITIONS_CONFIG init parameter. The files that have an underscore (_) in their name will be skipped. You can specify, for example:
  • If you are using Java-based configuration, override the getSourceURLs of BasicTilesContainerFactory. In the following example, notice the manual exclusion of files including underscores (_):
    /** {@inheritDoc} */
    protected List<URL> getSourceURLs(Object context,
            TilesApplicationContext applicationContext,
            TilesRequestContextFactory contextFactory) {
        List<URL> urls = new ArrayList<URL>(URL_COUNT);
        try {
            Set<URL> urlSet = applicationContext
            for (URL url : urlSet) {
                String externalForm = url.toExternalForm();
                if (externalForm.indexOf('_', externalForm.lastIndexOf("/")) < 0) {
        } catch (IOException e) {
            throw new DefinitionsFactoryException(
                    "Cannot load definition URLs", e);
        return urls;


Wildcard support uses Spring Framework syntax for loading files. For example:

  • one asterisk (*) for a single placeholder;
  • two asterisks (**) to say "in every directory under the specified one";
  • the classpath: prefix loads files from the classpath.
  • etc.

    For everything else, see Spring's documentation.