Contexts and Dependency Injection (CDI)

Learn about Contexts and Dependency Injection 1.2 for the Java™ EE platform (CDI 1.2), which is a JSR 346 implementation that is based on JBoss Weld.

CDI is activated in an application either by the presence of a beans.xml file inside that module, or by bean defining annotations that are defined in the JSR 346 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. Use beans.xml or @Priority to enable the decorators.
  • Interceptor bindings: Interceptors, which are enabled manually in the beans.xml file or enabled globally with @Priority, are bound by using an interceptor binding type.
  • Event model
  • Integration into JavaServer Faces (JSF) and JavaServer Pages (JSP) files that use the Expression Language (EL)
  • JavaEE component classes that support injections and the use of interceptors
Important: Container-managed transactions and security are not provided by CDI.
Avoid trouble: CDI is only supported by the default WebSphere® Application Server traditional class loader policy, Class loader for each WAR file in application, and not with the alternative, single class loader for application setting.