CDI Training

This repository holds the sample application which covers the main concepts of the CDI 2.0 specification. After working through the tasks one should be able to understand the main concepts of the CDI 2.0 specification and to use the CDI 2.0 concepts in real time applications.

The application is based on the Jakarta-EE 8.0 (CDI 2.0) specification and the Wildfly 22.0.0.Final application server.

Take a look at these slides for an introduction to CDI.

Covered CDI Basics

The following CDI concepts are covered by this example

  1. Injection

  2. Scopes

  3. Initialization (@PostConstruct, @PreDestroy)

  4. Qualifiers

  5. Producer Methods/Fields

  6. Interceptors

  7. Decorators

  8. Events

CDI Use Cases

Additionally, to the CDI basics, this sample application provides implementations with explanations for use cases we faced in our projects.

  1. Scopes and Concurrency
    How to provide request scoped state when using concurrency where we only can use @Dependent, @ApplicationScoped beans?

  2. Dynamic Default
    How to change the @Default of an CDI bean during runtime?

  3. Alternatives
    How and when to use @Alternative beans?

  4. Specialized
    How and when to use @Specialized beans, and what differs them from @Alternative beans?

  5. Registrar
    How to use a registrar to capture asynchronous executions results, which are needed by other parts of the application?

  6. Startup-Event
    How to notify the application about that the application has started?

  7. Lookup-Factory
    How to implement a factory to encapsulate the CDI programmatic bean lookup and how to manage @Dependent scoped beans properly?

Used Tools

To get the application running you need the following software installed:

Accessing the application

The application can be accessed via http://localhost:8080/cditraining/welcome.

Follow the instructions to work through the exercises.

Important
When running in an IDE the actual port will depend on your configuration.

Running in standalone

Run the application with ./mvnw wildfly:run.

Important
In this mode you won’t be able to hot-code deploy.

Running in an IDE

Refer to the documentation of the IDE of your choice, which must provide integration for Wildfly/JBoss servers, for how to set up the project.