Configuring Liberty for Contexts and Dependency Injection 2.0
You can configure Liberty for the Contexts and Dependency Injection (CDI) 2.0 feature, which provides full support for the Contexts and Dependency Injection 2.0 specification.
About this task
To configure the Liberty server to run an
application that is enabled for CDI 2.0, you must set the cdi-2.0
feature.
Procedure
Update the server.xml file to add the
cdi-2.0
feature.
<featureManager>
<feature>cdi-2.0</feature>
</featureManager>
Note:
- You can use other Java™ EE 8 features, such as
servlet-4.0
andjsf-2.3
, with thecdi-2.0
feature. However, you cannot use Java EE 7 features or Java EE 6 features with thecdi-2.0
feature. - You can use Java EE 7 features, such as
jsp-2.3
andjsf-2.2
, with thecdi-1.2
feature. - You can use Java EE 6 features, such as
jsp-2.2
andjsf-2.0
, with thecdi-1.0
feature. - You can choose between the CDI 2.0, CDI 1.2, and CDI 1.0 feature implementations for each server
instance, but you must consider the behavior changes. CDI 2.0 and CDI 1.2 are built on the Weld
implementation of CDI. CDI 1.0 is built on the Apache OpenWebBeans implementation of CDI. If the
behavior is only contained in the
cdi-2.0
feature, then you must use thecdi-2.0
feature. If an existing application might be adversely affected by behavior changes in thecdi-2.0
feature, then use either thecdi-1.2
orcdi-1.0
feature to preserve the existing behavior for that application. - It is not possible to use the
cdi-2.0
feature with the earliercdi-1.2
andcdi-1.0
features in the same Liberty server. If more than one CDI feature is configured, it produces an error. Read the CDI behavior changes topic to learn about changes from CDI 1.0 to CDI 2.0.
Results
The CDI 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 an empty beans.xml file.
- The application contains at least one class with bean-defining annotations.