Context and Dependency Injection (CDI)
Context and Dependency Injection (CDI) provides a common mechanism to inject component such as Enterprise JavaBeans (EJBs) or managed beans into other components such as JavaServer Pages (JSPs) or other EJBs.
CDI support is provided by Liberty, and is configured in the Liberty server configuration files
(server.xml and included files) through the features that are described in Table 1.
| Feature Name | CDI Specification Level | Specification Levels |
|---|---|---|
cdi-1.0 |
CDI 1.0 Note: CDI 1.0 support in Liberty is stabilized. For more information, see Stabilized Liberty features and feature
capabilities.
|
|
cdi-1.2 |
CDI 1.2 |
|
cdi-2.0 |
CDI 2.0 |
|
cdi-3.0 |
CDI 3.0 |
|
CDI beans can be packaged in any of the following archive types: JARs, EJB JARs, or WARs. Any location on the application class path can contain CDI beans. For CDI beans to be registered into the container, the archive they are contained in must be declared as a bean archive. In CDI 1.0, only explicit bean archives are supported. CDI 1.1 introduces support for two types of bean archives, explicit bean archives and implicit bean archives.
- META-INF/beans.xml for JAR types
- WEB-INF/beans.xml, or WEB-INF/classes/META-INF/beans.xml for WAR types.
Implicit bean archives must contain one or more bean classes with a bean defining annotation, or session bean.
Liberty provides a configuration option on whether implicit bean archives are enabled. In the CICS® default server.xml template file, implicit bean archives are disabled. If implicit bean archives are enabled in Liberty, every application is scanned for the presence of CDI beans, causing unnecessary CPU usage. On a platform where CPU is chargeable, a more efficient approach is to disable implicit bean archives, and define applications that contain CDI beans as explicit bean archives by adding a beans.xml file.
Implicit bean archives can be enabled through the following configuration:
<cdi12 enableImplicitBeanArchives="true" />
Methods within CDI beans can be defined as entry points to CICS programs. For more information, see Linking to Java applications in a Liberty JVM server by using the @CICSProgram annotation.