Build Status Test Status Maven Central JavaDocs License

Apache Sling Resource Resolver

This module is part of the Apache Sling project.

This bundle provides the Resource Resolver and Resource Resolver Factory

ETC Map String Interpolation

Setting up ETC Mappings (/etc/map) for different instances like dev, stage, qa and production was time consuming and error prone due to copy-n-paste errors. As a new feature Sling now supports String Interpolation in the /etc/map. With this it is possible to add placeholders to sling:match entries to make it possible to have them work for different environments. The values are either provides by System, Bundle Context or String Interpolation Configuration values. The placeholders have this format: $[‘type’:‘name’;default=‘default value’]. The type is can be:

  • env: take from the System Properties
  • prop: taken from the Bundle Context Properties
  • otherwise: taken from the String Interpolation Configuration

With it it is possible to create a single set of etc-mapping and then adjust the actual values of an instance by an OSGi configuration. Note: the placeholder must be placed into a sling:match entry and cannot be the JCR Node Name as some of the characters are not allowed.


The Substitution Configuration can be found in the OSGi Configuration as Apache Sling String Interpolation Provider. The property Placeholder Values takes a list of key=value entries where each of them map a variable with its actual value. In our little introduction we add an entry of Save the configuration for now. Before going on make sure that you know Mapping Location configuration in the OSGi configuration of Apache Sling Resource Resolver Factory. Now to to composum and go to that node. If it does not exist then create one. The mapping should look like this:

  • etc
    • map
      • http
        • my-mapping
          • sling:match=$[].8080

Opening the page http://localhost:8080/starter/index.html should work just fine. This is a mapping from System Properties with a default:

  • etc
    • map
      • http
        • my-mapping
          • sling:match=$[;default=localhost].8080


Now got back to the String Interpolation configuration and change the value to and save it.

For local testing open your hosts file (/etc/hosts on Unix) and add a line like this:

save it and test with ping to make sure the name resolves. Now you should be able to open the same page with:

Now do the same with

The String Interpolation works with any part of the etc-map tree.