为什么会有不同的bean管理注释 [英] Why are there different bean management annotations

查看:114
本文介绍了为什么会有不同的bean管理注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

两者之间有什么区别

import javax.annotation.ManagedBean;
import javax.enterprise.context.SessionScoped;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

?

推荐答案

  1. javax.enterprise.context.SessionScoped( JSR 346 )和所有javax.enterprise.context.*包下的其他注释保留了 CDI 的上下文. CDI为Java EE空间中的依赖项注入,bean和常规资源管理提供了一种替代的,通用的,更强大的机制.它是JSF托管bean的替代方案,它甚至可以取代 JSF即将发布的版本中的JSF bean管理机制.

  1. javax.enterprise.context.SessionScoped(JSR 346) and all other annotations under the javax.enterprise.context.* package maintain the context of CDI. CDI provides an alternative, versatile and more powerful mechanism for dependency injection, bean and general resource management within the Java EE space. It's an alternative to JSF managed beans and it's set to even supersede the JSF bean management mechanism in the coming version of JSF.

当前,在任何给定的Java EE Web应用程序中,JSF和CDI注释的bean都是可以互换的(有一些小的限制).但是,带有CDI注释的Bean远远超出了Web层的范围,这就是Java EE规范不断发展以使CDI成为标准Bean和DI机制的原因.

Currently, JSF and CDI annotated beans are interchangeable within any given Java EE web application (given a handful of minor restrictions). CDI annotated beans however, extend far beyond the realm of the web tier, which is why the Java EE spec is evolving to make CDI the standard bean and DI mechanism.

尽管CDI可能是所有Java EE开发的明显选择,但JSF管理的bean可跨servlet容器(Tomcat)和应用程序服务器(Glassfish,JBoss等)移植. CDI bean只能存在于完整的应用程序服务器中.借助一些麻烦事但是,可以将Tomcat 7连接起来以支持CD​​I.

While CDI might be an obvious choice for all Java EE development, JSF managed beans are portable across servlet containers (Tomcat) and application servers (Glassfish, JBoss, etc.). CDI beans can live within only full application servers. With some legwork however, Tomcat 7 can be wired to support CDI.

具体来说,javax.enterprise.context.SessionScoped是CDI中JSF Session Scope的并行实现.

Specifically, javax.enterprise.context.SessionScoped is the parallel implementation of the JSF Session Scope within CDI.

javax.faces.bean.SessionScoped(

javax.faces.bean.SessionScoped (JSR 314) and all other annotations under the javax.faces.bean.* package maintain the JSF-specific dependency injection and bean management mechanism. Beans annotated with JSF annotations however are only useful within the web tier. All the scopes available with JSF annotations have been replicated within the CDI specification.

javax.annotation.ManagedBean( JSR 316 )和其他javax.annotation.*下与DI相关的注释是对Java EE规范中其他用途的基于JSF的注释进行通用化的尝试,并且最终开发人员确实不应使用.

javax.annotation.ManagedBean (JSR 316) and other DI-related annotations under javax.annotation.* are an attempt to generalize the JSF-based annotations for other uses within the Java EE spec and really shouldn't be used by the end-developer.

为什么它们存在? IMO,从JSF bean到CDI bean的迁移是该技术的自然演进. JSF bean运行良好,但是像Spring,Guice和Seam这样的公司显然表明该技术还不够.还需要弥合Web组件和EJB之间的鸿沟,对此需求的响应是CDI.

Why they exist? Well IMO, the move from JSF beans to CDI beans is a natural evolution of the technology. JSF beans have had a good run but the likes of Spring, Guice and Seam made it obvious that the technology was not sufficient. There was also a need to bridge the gap between the web components and EJBs, and the response to that need is CDI.

也请参阅以下相关问题:

See these related questions too:

  • JSF: Backing beans (@ManagedBean) or CDI Beans (@Named)?
  • Java EE 6 @javax.annotation.ManagedBean vs. @javax.inject.Named vs. @javax.faces.ManagedBean

这篇关于为什么会有不同的bean管理注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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