New in Pax CDI 0.4.0

Background

OSGi Core 4.3 introduced bundle requirements and capabilities as a generalization of imported and exported packages or required bundles. Lists of capabilities provided or required by a given bundle are declared in special bundle manifest headers. Pax CDI uses the capability concept

CDI Extender Capability

Each bean bundle must require a CDI extender capability

Require-Capability : osgi.extender; filter:="(osgi.extender=pax.cdi)"

This capability is provided by the pax-cdi-extender which uses the OSGi extender pattern to CDI-enable other bundles. The bean bundle will fail to resolve if there is no bundle providing a matching capability.

Theoretically, any other bundle might provide the matching pax.cdi extender capability, so there is just a very loose coupling between bean bundles and pax-cdi-extender.

The marker manifest header Pax-ManagedBeans is deprecated since Pax CDI 0.4.0.

Up to Pax CDI 0.3.0, if you forgot to provision the CDI extender bundle, you would not even see a clear error message in this case.

Portable CDI extension bundles

A portable CDI extension bundle must provide a CDI extension capability to be considered by the OSGI CDI extender:

Provide-Capability : org.ops4j.pax.cdi.extension; extension=foo

The value of the extension attribute should be any suitable logical name, preferably not the bundle symbolic name.

An extension bundle may or may not be a bean bundle. This is in keeping with the CDI Specification stating that an extension does not necessarily have to be located in a bean deployment archive.

 

Bean bundles using a portable CDI extension

A bean bundle wishing to use a CDI extension for its CDI container must require the corresponding extension capability, or else the CDI extender will ignore the extension bundle.

Require-Capability : org.ops4j.pax.cdi.extension; filter:="(extension=foo)"

Pax CDI OSGi Extension

Pax CDI itself provides an portable CDI extension for publishing and consuming OSGi services by means of CDI annotations. A bean bundle wishing to use this extension must require the following extension capability:

Require-Capability : org.ops4j.pax.cdi.extension; filter:="(extension=pax-cdi-extension)"

Note that it is perfectly legal for a bean bundle not to use this extension. In this case the bean bundle only uses CDI internally or contributes CDI beans to other bundles which import packages from the given bundle.