The default scope is the dependent pseudo-scope @Dependent
, as stated in the weld documentation:
CDI features the so-called dependent pseudo-scope. This is the default
scope for a bean which does not explicitly declare a scope type. [...]
An instance of a dependent bean is never shared between different
clients or different injection points. It is strictly a dependent
object of some other object. It is instantiated when the object it
belongs to is created, and destroyed when the object it belongs to is
destroyed.
The javadoc for this annotation gives some more information about this scope:
Beans declared with scope @Dependent behave differently to beans with
other built-in scope types. When a bean is declared to have scope
@Dependent:
- No injected instance of the bean is ever shared between multiple injection points.
- Any instance of the bean injected into an object that is being created by the container is bound to the lifecycle of the newly
created object.
- When a Unified EL expression in a JSF or JSP page that refers to the bean by its EL name is evaluated, at most one instance of the
bean is instantiated. This instance exists to service just a single
evaluation of the EL expression. It is reused if the bean EL name
appears multiple times in the EL expression, but is never reused when
the EL expression is evaluated again, or when another EL expression
is evaluated.
- Any instance of the bean that receives a producer method, producer field, disposer method or observer method invocation exists to
service that invocation only.
- Any instance of the bean injected into method parameters of a disposer method or observer method exists to service the method
invocation only.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…