Documentation


Introduction

Apache DeltaSpike project has been created to support the development of portable CDI extensions that provide useful features for Java applications not provided out of the box by the CDI spec (Security, JPA, ...). CDI extensions created by the DeltaSpike community are packaged as modules.

The goal of the project is also to provide useful classes to :

* Boot CDI Container (Weld, OpenWebbeans, OpenEJB) for Java SE,
* Stage a project,
* Provide new scopes (Window Scope, ...),
* Manage messages and configurations

The project is currently tested on different CDI implementations like Apache OpenWebBeans and JBoss Weld, and also on different Java Web containers like Apache TomEE or JavaEE, JBoss-AS7, Oracle GlassFish 3.1+, Oracle Weblogic Server 12c.

[TODO] Define what portable means like also CDI extension and refers to documentation links

Getting Started

A DeltaSpike project can be designed using or not Apache Maven and consists in a collection of jar files. Depending on your needs, you will package DeltaSpike core jar (api and impl) files or extend the list with DeltaSpike modules. DeltaSpike Api and Impl are mandatory and provide code required to benefits of portable CDI extensions or useful features created.

Remark : For Java SE, an additional step is required as you have to select the CDI implementation of your choice to boot a CDI container.

[TODO] Add a section or remark to explain how to package & deploy DeltaSpike in an OSGI environment (Apache Felix, Apache Karaf, Apache ServiceMix)

Project Configuration without Maven

You can manually download all JARs described above from the maven repository or you get the source-code and build DeltaSpike manually.

Project Configuration with Maven

Hint: In the listings below replace the placeholders for the version with the version of your choice or use:

<properties>
    <deltaspike.version>0.4-incubating-SNAPSHOT</deltaspike.version>
</properties>

Configuration of DeltaSpike Core

<dependency>
    <groupId>org.apache.deltaspike.core</groupId>
    <artifactId>deltaspike-core-api</artifactId>
    <version>${deltaspike.version}</version>
    <scope>compile</scope>
</dependency>

<dependency>
    <groupId>org.apache.deltaspike.core</groupId>
    <artifactId>deltaspike-core-impl</artifactId>
    <version>${deltaspike.version}</version>
    <scope>runtime</scope>
</dependency>

Configuration of DeltaSpike Modules

Security Module

<dependency>
    <groupId>org.apache.deltaspike.modules</groupId>
    <artifactId>deltaspike-security-module-api</artifactId>
    <version>${deltaspike.version}</version>
    <scope>compile</scope>
</dependency>

<dependency>
    <groupId>org.apache.deltaspike.modules</groupId>
    <artifactId>deltaspike-security-module-impl</artifactId>
    <version>${deltaspike.version}</version>
    <scope>runtime</scope>
</dependency>

JPA Module

<dependency>
    <groupId>org.apache.deltaspike.modules</groupId>
    <artifactId>deltaspike-jpa-module-api</artifactId>
    <version>${deltaspike.version}</version>
    <scope>compile</scope>
</dependency>

<dependency>
    <groupId>org.apache.deltaspike.modules</groupId>
    <artifactId>deltaspike-jpa-module-impl</artifactId>
    <version>${deltaspike.version}</version>
    <scope>runtime</scope>
</dependency>

JSF Module

<dependency>
    <groupId>org.apache.deltaspike.modules</groupId>
    <artifactId>deltaspike-jsf-module-api</artifactId>
    <version>${deltaspike.version}</version>
    <scope>compile</scope>
</dependency>

<dependency>
    <groupId>org.apache.deltaspike.modules</groupId>
    <artifactId>deltaspike-jsf-module-impl</artifactId>
    <version>${deltaspike.version}</version>
    <scope>runtime</scope>
</dependency>

With Java SE

To use DeltaSpike with Java SE, we must provide additional jars file corresponding to the DeltaSpike CDI Controller API and its implementation. The Controller uses Java Services to resolve the CDI container (JBoss Weld, Apache OpenWebbeans (and Apache OpenEJB)) and implementation contains the code to manage the CDI container and contexts.

Hint: In the listings below replace the placeholders for the version with the version of your choice or use:

<properties>
    <deltaspike.version>incubating-0.4-SNAPSHOT</deltaspike.version>
    <owb.version>1.1.6</owb.version>
    <weld.version>1.1.9.Final</weld.version>
</properties>

Add the DeltaSpike Container Ctrl API

<dependency>
    <groupId>org.apache.deltaspike.cdictrl</groupId>
    <artifactId>deltaspike-cdictrl-api</artifactId>
    <version>${deltaspike.version}</version>
    <scope>compile</scope>
</dependency>

Add a CDI container + Container Ctrl Impl

... for Apache OpenWebBeans

<dependency>
    <groupId>org.apache.openwebbeans</groupId>
    <artifactId>openwebbeans-impl</artifactId>
    <version>${owb.version}</version>
    <scope>runtime</scope>
</dependency>

<dependency>
    <groupId>org.apache.openwebbeans</groupId>
    <artifactId>openwebbeans-spi</artifactId>
    <version>${owb.version}</version>
    <scope>compile</scope>
</dependency>

<dependency>
    <groupId>org.apache.deltaspike.cdictrl</groupId>
    <artifactId>deltaspike-cdictrl-owb</artifactId>
    <version>${deltaspike.version}</version>
    <scope>runtime</scope>
</dependency>

... for JBoss Weld (RI)

<dependency>
    <groupId>org.apache.deltaspike.cdictrl</groupId>
    <artifactId>deltaspike-cdictrl-weld</artifactId>
    <version>${deltaspike.version}</version>
    <scope>runtime</scope>
</dependency>

<dependency>
    <groupId>org.jboss.weld.se</groupId>
    <artifactId>weld-se</artifactId>
    <version>${weld.version}</version>
    <scope>runtime</scope>
</dependency>

Deployment mode

DeltaSpike can be deployed in different Java environments. Depending which Java container and release you are using, the procedure which is different is explained here after.

With Java EE6+

If you are using DeltaSpike in a Java EE6 environment, you don't need to configure a CDI implementation explicitly because it's shipped with the container.

With Java EE5 or Servlet Containers

Java EE5 application servers as well as pure servlet containers like Apache Tomcat / Eclipse Jetty don't provide a CDI implementation out-of-the-box. So don't forget to setup the CDI implementation of your choice.

Standard Java SE6+

If you are only using a JDK and runs Java in a standalone or standard mode (Java SE), then DeltaSpike will allow you to boot a CDI implementation where you can use Dependency Injection with a Bean Manager. Such an example will be presented at the next section.

Start a CDI container using Java SE

This code snippet show you how with a Java MainApplication a CDI container can be started (= boot) by DeltaSpike using Java SE and how you define a CDI scope and resolve beans injected.

Hint: To bootstrap a CDI container in your Java application, you just need to instantiate the CdiContainer and call the #boot method.

import org.apache.deltaspike.cdise.api.CdiContainer;
import org.apache.deltaspike.cdise.api.CdiContainerLoader;

public class MainApp {
    public static void main(String[] args) {

        CdiContainer CdiContainer = CdiContainerLoader.getCdiContainer();
        CdiContainer.boot();

        // You can use CDI here

        CdiContainer.shutdown();
    }
}

When #boot is called, the CdiContainer will scan CDI enabled archives for beans and CDI extensions.

Note: Booting the container does not automatically start all CDI Contexts!

Example for starting the application-context:

import org.apache.deltaspike.cdise.api.CdiContainer;
import org.apache.deltaspike.cdise.api.CdiContainerLoader;
import org.apache.deltaspike.cdise.api.ContextControl;
import javax.enterprise.context.ApplicationScoped;

public class MainApp {
    public static void main(String[] args) {

        CdiContainer CdiContainer = CdiContainerLoader.getCdiContainer();
        CdiContainer.boot();

        // Starting the application-context allows to use @ApplicationScoped beans
        ContextControl contextControl = cdiContainer.getContextControl();
        contextControl.startContext(ApplicationScoped.class);

        // You can use CDI here

        CdiContainer.shutdown();
    }
}

To resolve a bean of this project, you can use the BeanProvider provided by DeltaSpike. The following example shows how to resolve the a bean without qualifiers. It depends on the application if EchoService is a concrete implementation or just an interface. In case of an interface the corresponding implementation will be resolved. The resolved bean is a normal CDI bean which means you can use all CDI concepts like @Inject in the class (and you don't need further usages of BeanProvider).

EchoService echoService = BeanProvider.getContextualReference(EchoService.class, false);

Before the application exits, you have to call #shutdown to destroy beans,... in a well-ordered fashion.

Module Overview

The core features of DeltaSpike project are packaged under the following different modules. Some of them are mandatory while others are optional

Core (required)

Definition : Contain the API and util classes of DeltaSpike project

Features :

  • BeanProvider & Manager
  • ProjectStage
  • Config & Property
  • Messages & I18n
  • Exception Handling & Control

View details »

Security (optional)

Definition : Intercept and check security

Features :

*

View details »

JPA (optional)

Definition :

Features :

*

View details »

JSF (optional)

Definition :

Features :

*

View details »

Container Control (optional)

Definition :

Features :

*

View details »

External

Blogs