Network Deployment (Distributed operating systems), v8.0 > Develop and deploying applications > Develop web applications > Develop web applications > Develop Contexts and Dependency Injection (CDI)
Contexts and Dependency Injection (CDI)
Contexts and Dependency Injection for the Java EE platform (CDI) is a JSR 299 implementation that is 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 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 WAS 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.
Contexts and Dependency Injection (CDI)
Troubleshoot contexts and dependency injection