Overview
also called Contexts and Dependency Injection (CDI)
contexts: bind lifecycle and interactions of stateful components to defined and extensible contexts
managed beans (managed objects)
defined by assigning a scope to a regular class
that can be later injected
dependency injection
EL language integration: allows any component to be used directly within JSF or JSP
decoration: ability to decorate injected components
interception: type safe interceptor bindings
event-notification model : decouple message consumer and producers
additional web conversation scope
service provider interface (SPI) to allow extension and integration
Beans (in CDI context)
Java EE component is a bean if its lifecycle may be managed by container.
(my understanding: to be injected into other beans)
More specifically, a bean has
a non-empty set of bean types
defines client-visible type of the bean
may be any regular Java classes (almost any type)
interface
concrete class
abstract class
may be declared final or have final methods
may be a parameterized type with type parameters and variables
may be an array type - element type should be identical to be considered type identical
may be a primitive type
may be a raw type
a non-empty set of qualifiers
a scope
optionally a bean EL name
a set of interceptor bindings
a bean implementation
CDI Managed Beans
Is implemented by a Java class (bean class).
(My understanding: to be injected into others)
A top-level Java class is a managed bean if:
it's defined to be managed bean by any Java EE specification, OR
meet all the following conditions (no special declaration required)
not too "abnormal"
not non-static inner class
a concrete class or annotated with @Decorator
not an EJB (annotated or in ejb-jar.xml)
has appropriate constructor
default constructor, or
a constructor annotated @Inject
Bean as Inject-able objects
The follows can be injected
(almost) any Java class
Session beans
Java EE resources
data sources
JMS
service topics
queues
connection factories
and the like
Persistence contexts (EntityManager)
Producer fields
objects returned by producer methods
web service references
remote enterprise bean references