Configuring Liberty for Contexts and Dependency Injection 1.2

You can configure Liberty for the Contexts and Dependency Injection (CDI) 1.2 feature, which provides full support for the Contexts and Dependency Injection 1.2 specification.

About this task

To configure the Liberty server to run an application that is enabled for CDI 1.2, you must set the cdi-1.2 feature.

Procedure

Update the server.xml file to add the cdi-1.2 feature.
<featureManager>
    <feature>cdi-1.2</feature>
</featureManager>
Note:
  • You can use other Java™ EE 7 features, such as jsp-2.3 and jsf-2.2 with the cdi-1.2 feature. However, you cannot use Java EE 6 features such as jsp-2.2 and jsf-2.0 with the cdi-1.2 feature.
  • You can choose between the CDI 1.0 and CDI 1.2 feature implementations for each server instance, but you must consider the behavior changes. If the behavior is only contained in the CDI 1.2 feature, then you must use the CDI 1.2 feature. If an existing application might be adversely affected by behavior changes in the CDI 1.2 feature, then use the CDI 1.0 feature to preserve the existing behavior for that application.
  • It is not possible to use both the CDI 1.0 and CDI 1.2 features in the same Liberty server. If both features are configured, it produces an error. Read the CDI 1.2 behavior changes topic to learn about changes from CDI 1.0 to CDI 1.2.

Results

The CDI 1.2 feature is enabled and loads in the Liberty server at run time.

What to do next

Deploy your application to the CDI-enabled Liberty server. Your application requires either of the following beans to be enabled for CDI.
  • The application has a beans.xml file with a bean discovery mode of all.
  • The application has a blank beans.xml file that contains at least one class with bean-defining annotations.