Date: Fri, 29 Mar 2024 04:48:18 +0000 (UTC) Message-ID: <2025333043.19.1711687698692@9be443a52dea> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_18_393786623.1711687698692" ------=_Part_18_393786623.1711687698692 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
Component properties are the primary mechanism for adding configuration = to an application. Property values can be defined in a composite file or DS= L. However, in many cases, property values need to be modified without open= ing a contribution archive. Fabric3 supports the ability to define pro= perty values in XML files that are deployed external to the contribution th= at references them.
External property values are specified using an XPath expression that po=
ints to a value in an XML file. With Java annotations, this is done using t=
he Source
annotation:
@Compon= ent(namespaces =3D {@Namespace(prefix =3D "foo", uri =3D "urn:foo")}) public class ComponentImpl implements ... { =20 =09@Property @Source("$app//foo:configuration/@installation.id") protected String installationId; }
The Source
annotation defines a configuration file, a=
pp.xml
, located in the runtime's config
directory  =
;(<image>/runtimes/<name>/config
) that contains th=
e value for the installationId
property. The a=
pp.xml
file could be similar to the following:
<conf= iguration xmlns:foo=3D"urn:foo" installationId=3D"test id"> =20 </configuration>
The XPath expression can also point to arbitrarily nested elements in a =
configuration file. Also note the use of namespaces. The Namespa=
ce
attribute on the Component
annotation is used t=
o define a namespace to use when applying the XPath expression.
A property source can also be defined using XML-based composites:
<comp= osite ... xmlns:f3-samples=3D"urn:samples.fabric3.org"> <component name=3D"GatewayService"> <implementation.java class=3D"..."/> <property name=3D"interval" source=3D"$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 targ= et namespace:
<conf= ig xmlns=3D"urn:fabric3.org" name=3D"app" targetNamespace=3D"urn:samples.fa= bric3.org"> <gateway timeout=3D"100"/> </config>
The app XML file is deployed separately from the contribution containing=
the Gateway
component. Note that it is possible for mult=
iple components to reference parts of the same external configuration file.=