Lesson 7: Add dependency injection between bundles
In the previous lesson, you learned how to use dependency injection within a bundle. Dependency injection between bundles requires an extra reference entry in the blueprint configuration file.
Before you begin
About this task
To add dependency injection between bundles:
Creating a bundle project
About this task
Procedure
Adding a service to the bundle
About this task
Procedure
Updating the bean to use the new service
About this task
Procedure
Updating the blueprint configuration file
About this task
Procedure
Deploying the application
Procedure
- In Enterprise Explorer, expand .
- Right click CounterServlet and select . The Run On Server dialog opens.
- Click Finish.
Results
The string greet.getText()=0 Hello World! is displayed in the browser. Each time the page is reloaded the value increments.
Switch to the Console view (
) to view the output from the server.
A successful outcome displays the output from CounterImpl.init(), GreetImpl.init(), and WorldImpl.init(), based on the initialization method entries for the CounterImpl, GreetImpl, and WorldImpl beans
in the blueprint file:1/10 13:07:26:250 EDT] 000000aa StepStartBLA A CWWMH0300I: Starting business-level application "WebSphere:blaname=CounterApp".
[3/31/10 13:07:27:000 EDT] 000000aa webapp I com.ibm.ws.webcontainer.webapp.WebGroupImpl WebGroup SRVE0169I: Loading Web Module: CounterWebBundle.
[3/31/10 13:07:27:046 EDT] 000000aa WASSessionCor I SessionContextRegistry getSessionContext SESN0176I: Will create a new session context for application key default_hostCounterWebBundle
[3/31/10 13:07:27:062 EDT] 000000aa webcontainer I com.ibm.ws.wswebcontainer.VirtualHost addWebApplication SRVE0250I: Web Module CounterWebBundle has been bound to default_host[*:9083,*:80,*:9446,*:5067,*:5066,*:443].
[3/31/10 13:07:27:078 EDT] 000000aa FileLocatorIm E CWPST0164E: The CounterWebBundle composition unit is not found.
[3/31/10 13:07:27:093 EDT] 000000aa StepStartBLA A CWWMH0196I: Business-level application "WebSphere:blaname=CounterApp" was started successfully.
[3/31/10 13:07:27:109 EDT] 00000066 SystemOut O WorldImpl.init() called
[3/31/10 13:07:27:109 EDT] 00000015 SystemOut O CounterImpl.init() called
[3/31/10 13:07:27:125 EDT] 00000015 SystemOut O GreetImpl.init() called
Note: If the output from the CounterImpl.init(), GreetImpl.init(), and WorldImpl.init() does
not display in the console output, check the output for error messages
during deployment or startup of the application and then check the
blueprint files for possible errors in the bean and service definitions.
Lesson checkpoint
You learned how to use blueprint dependency injection to allow one bean to use the services of another.
In this lesson, you learned how to use a blueprint
Reference to configure cross bundle dependency injection.