Service Configuration Files

Overview

Component properties are the primary mechanism for adding configuration to an application. Property values can be defined in a composite file or DSL. However, in many cases, property values need to be modified without opening a contribution archive. Fabric3 supports the ability to define property values in XML files that are deployed external to the contribution that references them.

Defining External Property Values with Annotations

External property values are specified using an XPath expression that points to a value in an XML file. With Java annotations, this is done using the Source annotation:

@Component(namespaces = {@Namespace(prefix = "foo", uri = "urn:foo")})
public class ComponentImpl implements ... {
    
	@Property
    @Source("$app//foo:configuration/@installation.id")
    protected String installationId;

}

The Source annotation defines a configuration file, app.xml, located in the runtime's config directory  (<image>/runtimes/<name>/config) that contains the value for the installationId property. The app.xml file could be similar to the following:

<configuration xmlns:foo="urn:foo" installationId="test id">
   
</configuration> 

The XPath expression can also point to arbitrarily nested elements in a configuration file. Also note the use of namespaces. The Namespace attribute on the Component annotation is used to define a namespace to use when applying the XPath expression.

Defining External Property Values with Composites

A property source can also be defined using XML-based composites:

<composite ... xmlns:f3-samples="urn:samples.fabric3.org">
    <component name="GatewayService">
        <implementation.java class="..."/>
        <property name="interval" source="$app//f3-samples:gateway/@timeout"/>
    </component>
</composite> 

The above example configures a property value to be sourced from the timeout attribute of the gateway element defined in the app XML file.  External configuration files must use the f3:config root element to define a name (in this case "app") and target namespace:

<config xmlns="urn:fabric3.org" name="app" targetNamespace="urn:samples.fabric3.org">
    <gateway timeout="100"/>
</config>

The app XML file is deployed separately from the contribution containing the Gateway component. Note that it is possible for multiple components to reference parts of the same external configuration file.