WAS v8.5 > Develop applications > Develop web applications > Develop web applications > Develop CDICDI
Contexts and Dependency Injection for the Java EE platform (CDI) is a JSR 299 implementation based on Apache OpenWebBeans.
CDI is activated in an application by the presence of a beans.xml file inside that module, as defined by the JSR 299 specification. We can find the beans.xml file in the WEB-INF directory of a web archive (WAR) or META-INF directory of other types of archives. When activated, the container provides services such as:
- Context management
- Type-safe dependency injection: A CDI-managed bean is instantiated and injected as needed.
- Decorators, which implement one or more bean interfaces and can contain business logic. Decorators are disabled by default. We can have multiple decorators per bean and order is defined by the beans.xml file.
- Interceptor bindings. Interceptors, which are enabled manually in the beans.xml file, are bound using an interceptor binding type.
- Event model
- Integration into JavaServer Faces (JSF) and JSP files using the Expression Language (EL)
The specification-related API classes for JSR 299 and JSR 330 and IBM modified implementation classes that are based on Apache OpenWebBeans are packaged with the application server runtime environment.
Although the WebSphere Application Server CDI implementation is based on Apache OpenWebBeans, there are some changes and additions on top of OpenWebBeans to support integration with the server run time:
- Integration with other Java EE containers in WAS that support injectable components.
- ScannerService implementation that uses the WAS byte code scanner.
- Direct use of WAS EJB metadata for determining EJB types.
- Automatic registration of Servlet Listeners, Filters, Interceptors for CDI applications so these no longer must be added by each application.
- WAS-specific implementations of many OpenWebBeans Service Programming Interfaces (SPI), such as ResourceInjectionService, TransactionService, failover service, and so on.
Container-managed transactions and security are not provided by CDI.
CDI is only supported with the default class loader policy, Class loader for each WAR file in application, and not with the alternative, single class loader for application setting.
Subtopics
- Contexts and Dependency Injection custom properties
WAS CDI implementation is based on OpenWebBeans, which is configurable through the openwebbeans.properties file.- CDI integration with JavaServer Faces
CDI primarily integrates with JavaServer Faces (JSF) through the Expression Language (EL). It enables CDI beans to be exposed through the unified EL-to-JSF components. It also provides a built-in context for conversation scope that is active during standard JSF life cycle phases.- CDI integration with EJB container
The CDI specification enhances the EJB component model with contextual life cycle management.
Related
Troubleshooting contexts and dependency injection
Related information:
Develop applications that use CDI
CDI