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
-
Right-click the project CounterServiceBundle and select and then click Finish. The blueprint configuration file opens in the editor.
-
Add the component assembly and configuration information
to the blueprint configuration file:
-
In the Design tab of the editor, click Add. The Add Item dialog opens.
-
Click Bean and then click OK. The Bean Details dialog opens.
-
Configure the bean:
- In the Bean ID field, type
CounterBean.
- 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.
- Click OK to accept the changes and close
the dialog.
- In the editor, in the Initialization method field, under the Method References section, type
init.
The bean is added to your blueprint file.
-
Click Blueprint and then click Add. The Add Item dialog opens.
-
Click Service and then click OK. The Service Details dialog opens.
-
Configure the service:
- In the Service Interface field, click Browse and
then select the Counter interface that you created in Lesson 2. Click
OK.
- In the Bean Reference field, click Browse and then select Bean: CounterBean. Click OK.
- Click OK to accept the changes and close
the dialog.
The service is added to your blueprint file.
-
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).