ejb - Details requried on javax.annotation.ManagedBean

╄→гoц情女王★ 提交于 2019-12-22 11:35:23

问题


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

  2. No, there is no container-managed concurrency.

  3. (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.

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.



来源:https://stackoverflow.com/questions/32400686/ejb-details-requried-on-javax-annotation-managedbean

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!