ejb - 需要在javax.annotation.ManagedBean上提供的详细信息 [英] ejb - Details requried on javax.annotation.ManagedBean

查看:165
本文介绍了ejb - 需要在javax.annotation.ManagedBean上提供的详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有很多关于无状态,有状态 Sigleton bean的信息,但几乎没有关于 javax.annotation.ManagedBean 。初看起来,我认为它类似于 Spring的 @Component 但如果没有完整的信息,我就无法使用它。

There is lot of information about Stateless, Stateful and Sigleton beans everywhere but almost nothing about javax.annotation.ManagedBean. At a first look I assumed that It's be similar to Spring's @Component but I can't use it without complete information.


  1. 如果我用 @javax.annotation.ManagedBean 注释一个类,它会是单例还是像无状态一样有实例池?

  2. 这类中的方法是并发的吗?我应该确保它们在单例中默认是同步的。

  3. 我想用这个来注释我的DAO类,但 @javax.enterprise.context。 *; 范围让我怀疑。我认为 @Stateless 会更好。有什么意见吗?

  4. 如果没有在DAO或服务类上,这个注释适合哪里?

  1. If I annotate a class with @javax.annotation.ManagedBean will it be singleton or it will have instance pool like stateless?
  2. Will the methods inside such class be concurrent? I should make sure as in a singleton they are synchronized by default.
  3. I was thinking of annotating my DAO class with this but the @javax.enterprise.context.*; scopes put me doubt. I think @Stateless will be better. Any comments?
  4. If not on DAO or service classes, where does this annotation fit in?



<这个答案提供了非常好的解释,但没有回答上述问题。

This answer gives very good explanation but doesn't answer the above questions.

推荐答案


  1. 两者都没有。它们是每个查找/注入实例,更像是有状态。

  1. Neither. They are per lookup/injection instances, more like stateful.

不,没有容器管理的并发。

No, there is no container-managed concurrency.

(和4.)您是否需要事务,安全性或其他EJB功能?然后 @Stateless 可能更好。否则,我会使用CDI,因为它几乎在所有方面都优于 @javax.annotation.ManagedBean 注释,并且它在EE 7中默认启用,因此它显然是EE的前进方向。

(and 4.) Do you need transaction, security, or other EJB capabilities? Then @Stateless is probably better. Otherwise, I would just use CDI since it is better than the @javax.annotation.ManagedBean annotation in nearly all ways, and it is enabled by default in EE 7, so it is clearly the forward direction for EE.

作为背景, @javax .annotation.ManagedBean 注释是在EE 6周期的开发后期添加的,并没有被广泛使用。托管bean规范旨在统一EJB,CDI和JSF托管bean组件模型的生命周期,注入和命名行为。这很有用,但在我看来, @javax.annotation.ManagedBean 注释只是一个事后的想法,允许开发人员在没有开销/复杂性的情况下访问最小组件模型功能(其他组件模型的真实或感知(EJB必然具有一组固定的必需服务和相关的开销,CDI在几乎所有方面都更好,但显然更复杂,并且JSF托管bean与WAR绑定)。然而,这个共同点是一个非常有限的组件模型,只有@ PostConstruct,@ Resource(和其他EE注入)和@Interceptors。没有安全性,事务,作用域/生命周期(如在EJB或CDI中),@ PreDestroy,与Web层的紧密集成等。

As a bit of background, the @javax.annotation.ManagedBean annotation was added late in the development of the EE 6 cycle, and it is not widely used. The managed bean spec was intended to unify the lifecycle, injection, and naming behaviors of the EJB, CDI, and JSF managed bean component models. That was useful, but in my opinion, the @javax.annotation.ManagedBean annotation was just an afterthought to allow developers to access the minimal component model functionality without the overhead/complexity (real or perceived) of the other component models (EJB necessarily has a fixed set of required services and associated overhead, CDI is better in nearly all ways but is clearly more complex, and JSF managed beans are tied to WAR). However, this "common denominator" is then a quite limited component model with just @PostConstruct, @Resource (and other EE injection), and @Interceptors. There's no security, transaction, scoping/lifecycle (as in EJB or CDI), @PreDestroy, tight integration with the web tier, etc.

这篇关于ejb - 需要在javax.annotation.ManagedBean上提供的详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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