OSGi application design guidelines

When developing OSGi applications for WebSphere® Application Server, consider these design guidelines to make the most efficient use of OSGi technology.

The design guidelines described in this topic are: Details for each of these guidelines are provided in the sections that follow.

Use OSGi services to configure EJB dependencies

If your OSGi application has a client bundle that references an EJB in a service bundle, use OSGi services to configure the EJB dependency.

To configure EJB dependencies by using OSGi services, complete the following steps:
  1. Declare the EJB in the Export-EJB header in the bundle manifest file of the service bundle, so that the EJB is registered in the OSGi service registry.
  2. Use a reference element in the Blueprint XML file of the client bundle to inject and call the EJB; for more information, see References and the Blueprint Container
Here’s why
Configuring EJB dependencies by using OSGi services reduces the risk of the web or EJB container of the client bundle being recycled, or the client bundle itself being restarted, either of which might result in the temporary unavailability of one or more application endpoints.

Do not use the java:global or java:app namespaces

Do not use the java:global or java:app namespace references to bind to EJBs unless necessary.

Here’s why
These namespace references have the following fixed formats:
java:global/application_name/module_name/ejb_name
java:app/module_name/ejb_name
However, the constituent parts of these references can change after an OSGi application is updated, so that the references must be modified accordingly, which makes this approach impractical. Furthermore, the exposure of the name of the underlying EJB in the reference, rather than using an abstraction such as an intermediate JNDI name, violates the principles of modular application design.

Instead, use OSGi services to configure EJB dependencies, or declare an EJB reference and map it to the EJB JNDI name.

Note: If you define java:global or java:app references in an @EJB annotation, or in a binding file, you receive a warning when you deploy the OSGi application as a business-level application.