The OSGi Configuration Admin service defines a mechanism for passing configuration settings to an OSGi bundle. You do not have to use this service for configuration, but it is typically the most convenient way of configuring applications deployed in Fuse ESB Enterprise (including FABs and OSGi bundles).
In the OSGi Configuration Admin service, a persistent ID is
a name that identifies a group of related configuration properties. In Fuse ESB Enterprise, every
persistent ID, PersistentID, is implicitly associated
with a file named in the
PersistentID.cfg directory. If the
corresponding file exists, it can be used to initialize the values of properties
belonging to the ESBInstallDir/etc/PersistentID property group.
For example, the etc/org.ops4j.pax.url.mvn.cfg file is used to set
the properties associated with the org.ops4j.pax.url.mvn persistent ID
(for the PAX Mvn URL handler).
Spring DM provides support for OSGi configuration, enabling you to substitute variables in a Spring XML file using values obtained from the OSGi Configuration Admin service.
Example 1 shows how to pass the value
of the prefix variable to the constructor of the
myTransform bean in Spring XML, where the value of
prefix is set by the OSGi Configuration Admin service.
Example 1. Using OSGi Configuration Properties in Spring XML
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ctx="http://www.springframework.org/schema/context"
xmlns:osgi="http://camel.apache.org/schema/osgi"
xmlns:osgix="http://www.springframework.org/schema/osgi-compendium"
... >
...
<bean id="myTransform" class="org.fusesource.example.MyTransform">
<property name="prefix" value="${prefix}"/>
</bean>
<osgix:cm-properties id="preProps" persistent-id="org.fusesource.example">
<prop key="prefix">MyTransform</prop>
</osgix:cm-properties>
<ctx:property-placeholder properties-ref="preProps" />
</beans>The syntax, ${prefix}, substitutes the value of the
prefix variable into the Spring XML file. The OSGi properties are
set up using the following XML elements:
osgix:cm-propertiesTo integrate Spring properties with the properties from the OSGi Configuration Admin service, insert an
osgix:cm-propertieselement into the Spring XML file. This element creates a bean that gets injected with all of the properties from the OSGiManagedServiceinstance that is identified by thepersistent-idattribute. The minimal configuration consists of an emptyosgix:cm-propertieselement that sets thepersistent-idattribute and theidattribute—for example:<osgix:cm-properties id="preProps" persistent-id="org.fusesource.example"/>
For an example of how the persistent ID relates to OSGi configuration settings, see the example in Add OSGi configurations to the feature.
If you want to define defaults for some of the properties in the Spring XML file, add
propelements as children of theosgix:cm-propertieselement, as shown in Example 1.ctx:property-placeholderProperty placeholder is a Spring mechanism that enables you to use the syntax,
${, to substitute variables in a Spring XML file. By defining aPropName}ctx:property-placeholderelement with a reference to theprePropsbean (as in Example 1), you enable the property placeholder mechanism to substitute any of the variables from theprePropsbean (which encapsulates the OSGi configuration properties) into the Spring XML file.
Example 2 shows how to pass the
value of the prefix variable to the constructor of the
myTransform bean in blueprint XML, where the value of
prefix is set by the OSGi Configuration Admin service.
Example 2. Using OSGi Configuration Properties in Blueprint
<blueprint
xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
... >
...
<cm:property-placeholder persistent-id="org.fusesource.example">
<cm:default-properties>
<cm:property name="prefix" value="Blueprint-Example"/>
</cm:default-properties>
</cm:property-placeholder>
<bean id="myTransform" class="org.apache.servicemix.examples.camel.MyTransform">
<property name="prefix" value="{{prefix}}" />
</bean>
</blueprint>The syntax, {{prefix}}, substitutes the value of the
prefix variable into the blueprint XML file. The OSGi properties
are set up using the following XML elements:
cm:property-placeholderThis element gives you access to the properties associated with the specified persistent ID. After defining this element, you can use the syntax,
{{, to substitute variables belonging to the specified persistent ID.PropName}}cm:property-placeholder/cm:default-propertiesYou can optionally specify default values for properties by defining
cm:propertyelements inside thecm:default-propertieselement. If the correspondingetc/file defines property values, however, these will be used instead.PersistentID.cfg








