命名CDI bean的默认范围是什么? [英] What is the default scope of a Named CDI bean?

查看:114
本文介绍了命名CDI bean的默认范围是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于 @Named CDI bean,没有额外的 @ ... Scoped 注释有任何默认的作用域?我没有在官方Weld文档中找到任何相关信息。

Is there any default scope for a @Named CDI bean without additional @...Scoped annotations? I have not found any relevant information in the official Weld documentation.

可以通过JSF访问一个 @Named bean,而不需要额外的注释,所以一些隐含的范围似乎很可能。

A @Named bean can be accessed over JSF without additional annotations, so some implicit scope seems likely.

谢谢

推荐答案

默认范围是依赖伪范围 @Dependent ,如焊接文档

The default scope is the dependent pseudo-scope @Dependent, as stated in the weld documentation:


CDI具有所谓的相关伪作用域。这是一个未明确声明范围类型的bean的默认
范围。 [...]
依赖bean的实例从不在不同的
客户端或不同的注入点之间共享。它是一个其他对象的严格依赖的
对象。当
属于的对象被创建时被实例化,当它所属的对象被销毁时被销毁

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.

此注释的javadoc 会提供有关此范围的更多信息:

The javadoc for this annotation gives some more information about this scope:


使用范围@Dependent声明的Bean与具有
其他内置作用域类型的bean的行为不同。当一个bean被声明为具有范围
@Dependent:

Beans declared with scope @Dependent behave differently to beans with other built-in scope types. When a bean is declared to have scope @Dependent:


  • 没有注入的bean实例在多个注入点之间共享

  • 注入到由容器创建的对象中的bean的任何实例都绑定到新的

    创建对象的生命周期。

  • 当评估引用其EL名称的bean的JSF或JSP页面中的Unified EL表达式时,实例化
    bean的最多一个实例。该实例存在于仅为EL表达式执行单个
    评估。如果bean EL名称

    在EL表达式中多次出现,则会被重用,但是当
    再次评估EL表达式时,或者当另一个EL表达式

    被评估。

  • 接收生产者方法,生产者字段,处理器方法或观察员方法调用的bean的任何实例都存在于仅调用的
    服务中。 / li>
  • 注入到处理器方法或观察器方法的方法参数中的bean的任何实例都存在于仅为

    调用的方法提供服务。

  • 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.

这篇关于命名CDI bean的默认范围是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆