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.
You 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. You 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 JavaServer Pages (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 Platform,
Enterprise Edition (Java EE)
containers in WebSphere Application
Server that support injectable components.
- ScannerService implementation that uses the WebSphere Application Server byte code
scanner.
- Direct use of WebSphere Application
Server Enterprise JavaBeans (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.
- WebSphere Application
Server-specific implementations of many OpenWebBeans Service Programming
Interfaces (SPI), such as ResourceInjectionService, TransactionService,
failover service, and so on.
Important: Container-managed transactions and security
are not provided by CDI.
Avoid trouble: ![[Updated in September 2012]](../../delta.gif)
CDI is only supported
with the default WebSphere Application
Server class loader policy,
Class loader for each WAR file
in application, and not with the alternative,
single
class loader for application setting.
![[Updated in September 2012]](../../deltaend.gif)
sep2012
gotcha