LibraryToggle FramesPrintFeedback

Example 2.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.


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-properties

To integrate Spring properties with the properties from the OSGi Configuration Admin service, insert an osgix:cm-properties element into the Spring XML file. This element creates a bean that gets injected with all of the properties from the OSGi ManagedService instance that is identified by the persistent-id attribute. The minimal configuration consists of an empty osgix:cm-properties element that sets the persistent-id attribute and the id attribute—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 prop elements as children of the osgix:cm-properties element, as shown in Example 2.1.

ctx:property-placeholder

Property placeholder is a Spring mechanism that enables you to use the syntax, ${PropName}, to substitute variables in a Spring XML file. By defining a ctx:property-placeholder element with a reference to the preProps bean (as in Example 2.1), you enable the property placeholder mechanism to substitute any of the variables from the preProps bean (which encapsulates the OSGi configuration properties) into the Spring XML file.

Example 2.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.


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-placeholder

This element gives you access to the properties associated with the specified persistent ID. After defining this element, you can use the syntax, {{PropName}}, to substitute variables belonging to the specified persistent ID.

cm:property-placeholder/cm:default-properties

You can optionally specify default values for properties by defining cm:property elements inside the cm:default-properties element. If the corresponding etc/PersistentID.cfg file defines property values, however, these will be used instead.

Comments powered by Disqus
loading table of contents...