Web Applications

Introduction

Pax CDI can be used with or without a web container.

In a minimal configuration, i.e. without a web container, Pax CDI supports bean bundles, a combination of OSGi bundles and CDI bean archives, offering all CDI features available in a Java SE (or non-Java-EE) environment.

In a web configuration, Pax CDI supports web bean bundles, a combination of CDI bean archives and web application bundles (WABs), offering all CDI features available in a servlet container, e.g. session and request scoped beans, injection into servlets etc., but not the features requiring a Java EE Web (or Full) Profile container, like injection of persistence contexts or EJBs and declarative transactions.

A web bean bundle is identified by two special manifest headers:

  • Pax-ManagedBeans, marking the bundle as a bean bundle
  • Web-ContextPath, marking the bundle as a web application bundle

Runtime Requirements

Runtime support for non-web bean bundles requires the following Pax CDI bundles:

  • pax-cdi-api
  • pax-cdi-spi
  • pax-cdi-extender
  • pax-cdi-extension
  • pax-cdi-openwebbeans or pax-cdi-weld

As of 0.4.0, Pax CDI requires Declarative Services, e.g. from mvn:org.apache.felix/org.apache.felix.scr/1.6.2.

Web bean bundles are enabled by the joint forces of Pax Web, Pax CDI and a CDI provider like OpenWebBeans or Weld. In addition to the Pax CDI bundles listed above, you need to provision

  • pax-cdi-web
  • pax-cdi-web-openwebbeans or pax-cdi-web-weld

pax-cdi-web has a compile-time dependency on Pax Web, by implementing the WebAppDependencyHolder interface provided by Pax Web (since 3.0.0.M1). Pax Web has no compile-time or run-time dependencies on Pax CDI. Since pax-cdi-web is an optional add-on for web bean bundles, there is only a very loose coupling between Pax CDI and Pax Web.

Pax CDI only works with the traditional Pax Web Jetty container. It does not yet support the Pax Web Tomcat container.