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

查看:19
本文介绍了为什么会有不同的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 版本.

  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.

目前,JSF 和 CDI 注释 bean 可以在任何给定的 Java EE Web 应用程序中互换(考虑到一些小限制).然而,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 可以连接起来支持 CDI.

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 (JSR 314) 和 javax.faces.bean.* 包下的所有其他注释维护JSF 特定的依赖注入和 bean 管理机制.但是,使用 JSF 注释的 Bean 仅在 Web 层内有用.JSF 注释的所有可用范围均已在 CDI 规范中复制.

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 相关注释试图将基于 JSF 的注释推广到 Java EE 规范中的其他用途,实际上不应该由最终开发人员使用.

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:

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

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