Lesson 3: Create the blueprint configuration file
The blueprint configuration file contains the component assembly and configuration information for a bundle. The file describes how components are registered in the OSGi service registry or how they look up services from the OSGi service registry. This information is used at run time to instantiate and configure the required components when the bundle is started. In this tutorial, the blueprint file defines a service that other components can use to access the counter that is defined in Lesson 2.
About this task
In this lesson, you create the blueprint configuration file that defines and describes the services that are provided by the CounterServiceBundle.
To create the blueprint configuration file:
Procedure
Results
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
<bean id="CounterBean" class="com.ibm.ws.eba.counter.CounterImpl" init-method="init"/>
<service id="CounterBeanService" ref="CounterBean"
interface="com.ibm.ws.eba.counter.Counter" />
</blueprint>
What to do next
- bean
- The bean element defines the blueprint component that is instantiated.
- In this tutorial, the bean element results in the instantiation of component Counter by calling the CounterImpl class constructor. After the class is created, the initialization method getCount() is invoked.
- class
- The class attribute specifies which implementation class of the component is instantiated.
- id
- The id attribute identifies the component. It is mandatory if the component is referenced from elsewhere in the blueprint, for example if it is referenced from a service definition.
- init-method
- The init-method init() is called when the component is created. If you do not want to invoke a method during bundle initialization, remove this attribute.
- service
- The service element defines the export of a component to the OSGi service registry.
- In this tutorial, the service element exports the component with the name Counter as a service in the OSGi service registry with interface com.ibm.ws.eba.counter.Counter, specified by the interface attribute.
- ref
- The ref attribute refers to the component id of the exported component. This id is defined in the component element.
- interface
- The interface attribute refers to the interface that the component class implements.
For more information about the blueprint configuration file, see OSGi Blueprint XML and OSGi Blueprint component model (RFC124).
Lesson checkpoint
You created the blueprint configuration file for the OSGi Counter bundle.
- How to create a blueprint.xml file.
- How to configure a blueprint.xml file.