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 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:
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:
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:
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.