< Previous | Next >

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

  1. Right-click the project CounterServiceBundle and select New > Blueprint File and then click Finish. The blueprint configuration file opens in the editor.
  2. Add the component assembly and configuration information to the blueprint configuration file:
    1. In the Design tab of the editor, click Add. The Add Item dialog opens.
    2. Click Bean and then click OK. The Bean Details dialog opens.
    3. Configure the bean:
      1. In the Bean ID field, type CounterBean.
      2. In the Bean Class field, click Browse. The Type Selection dialog opens. In the Choose type name field, type CounterImpl and then select the CounterImpl class. Click OK.
      3. Click OK to accept the changes and close the dialog.
      4. In the editor, in the Initialization method field, under the Method References section, type init.
      The bean is added to your blueprint file.
    4. Click Blueprint and then click Add. The Add Item dialog opens.
    5. Click Service and then click OK. The Service Details dialog opens.
    6. Configure the service:
      1. In the Service Interface field, click Browse and then select the Counter interface that you created in Lesson 2. Click OK.
      2. In the Bean Reference field, click Browse and then select Bean: CounterBean. Click OK.
      3. Click OK to accept the changes and close the dialog.
      The service is added to your blueprint file.
  3. Save the file.

Results

Switch to the Source tab to view the blueprint configuration source:
<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>
Tip: To format the source press Ctrl + Shift + F.

What to do next

Learn more about this blueprint configuration file:
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.

In this lesson, you learned about the following topics:
  • How to create a blueprint.xml file.
  • How to configure a blueprint.xml file.
< Previous | Next >
Icon that indicates the type of topic Tutorial lesson topic
Timestamp icon Last updated: July 17, 2017 21:58

File name: counter_lesson3.html