Apache
Home » Documentation » Bundles

Apache Sling Context-Aware Configuration - Default Implementation

About

By default the 'default implementation' us used by the Context-Aware Configuration concerning lookup and persistence of configuration data, resource and property inheritance and context path detection. Using the SPI it is possible to overlay, extend or replace this functionality.

This page documents the details of the default implementation.

Repository paths

By default all configuration data is stored in /conf. Fallback paths are /conf/global, /apps/confand /libs/conf.

The paths are configurable in the service configuration.

Context paths

The content resource hierarchy is defined by setting sling:configRef properties. Each resource that has a sling:configRef property set defines the root resource of a context, the whole subtree is the context. Within the subtree further nested contexts can be defined.

Configuration resource resolving

This illustration shows an example for configuration resource lookup:

Configuration resource lookup

If you get the context-aware configuration via the API for any resource below /content/tenant1/region1/site1 it is looked up in this path in this order:

  1. /conf/brand1/tenant1/region1/site1 - because referenced by /content/tenant1/region1/site1
  2. /conf/brand1/tenant1/region1 - because referenced by /content/tenant1/region1 (parent context)
  3. /conf/brand1/tenant1 - because referenced by /content/tenant1 (parent context)
  4. /conf/brand1 - because it is a parent of by /conf/brand1/tenant1
  5. /conf/global - because it is configured as fallback path
  6. /apps/conf - because it is configured as fallback path
  7. /libs/conf - because it is configured as fallback path

So the basic rules are:

Configuration persistence

Example for the resource structure for a configuration resource at /conf/mysite:

/conf
    /mysite
        /sling:configs
            /x.y.z.MyConfig
              @prop1 = 'value1'
              @prop2 = 123
              @prop3= true

Explanation:

Resource inheritance

We distinguish between:

For singleton resources, there is not resource inheritance. The first resource that is found in the configuration resource resolving lookup order is returned.

For collection resources there is no resource inheritance enabled by default. The children of the first resource that is found in the configuration resource resolving lookup order are returned.

By defining a property sling:configCollectionInherit on the configuration resource, the children of the next resource that is found in the configuration resource resolving lookup order are combined with the children of the current configuration resource, returned a merged list. If both configuration resources contain child resources with the same name, duplicates are eliminated and only the children of the first resource are included.

By setting the property sling:configCollectionInherit on multiple configuration resources that are part of the lookup order it is possible to form deeper inheritance chains following the same rules.

Example for resource inheritance:

Resource inheritance

The result of this example is: C, A, B. It would by just C if the sling:configCollectionInherit is not set.

Property inheritance

By default, no property inheritance takes place. That means only the properties that are stored in the configuration resource are mapped to the annotation class or returned as value map, regardless whether singleton or collection resources are returned, or if resource collection inheritance is enabled or not.

By defining a property sling:configPropertyInherit on the configuration resource, property merging is enabled between the current configuration resource and the next resource with the same name (singleton or resource collection item) in the configuration resource lookup order. That means that all properties that are not defined on the current configuration resource are inherited from the next resources and a merged value map is used for the configuration mapping.

By setting the property sling:configPropertyInherit on multiple configuration resources that are part of the lookup order it is possible to form deeper inheritance chains following the same rules.

Rev. 1795449 by sseifert on Wed, 17 May 2017 20:01:18 +0000
Apache Sling, Sling, Apache, the Apache feather logo, and the Apache Sling project logo are trademarks of The Apache Software Foundation. All other marks mentioned may be trademarks or registered trademarks of their respective owners.