JEE6:@Resource可以注入什么?
我试图找出什么可以通过 @Resource 注释注入到无状态会话 Bean 中。我在哪里可以找到清单?它是否取决于容器(在我的例子中是 Glassfish 3.1.1)?
I'm trying to find out, what can be injected via the @Resource
annotation into a Stateless Session Bean. Where would I find a list? Does it depend on the container (in my case it's Glassfish 3.1.1)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
JSR-250(Java 平台的通用注释) 解决了使用@Resource注解处理类时的容器;相关部分是 2.3,其中讨论了
@Resource
注释。总的来说,部署描述符中可以作为
env-entry
、service-ref
、resource-ref
、< code>message-destination-ref 或resource-env-ref
可以使用@Resource
注解进行注解以进行注入。其实例可以注入受支持的类的特定 Java 类型的列表也在同一部分中指定,并复制如下:注意表中的最后一项 - 根据规范,与资源关联的任何管理对象,即存在于 JNDI 目录中的可以被注入。
此类类的明确列表,其实例必须由容器注入,可以从 Java EE 6 平台规范。这没有以任何形式列出,但尽管如此,本章指定了应用程序开发人员必须如何请求注入任何重要资源。本章中列出的大多数资源都是通过指定 @Resource 注释或显式用于该资源的另一个注释来注入的。
EJB 3.1规范可能会重复上述平台规范第5章的内容,针对特定于 EJB 容器的资源。相关详细信息在标题为“企业 Bean 环境”的第 16 章中,相关详细信息出现在标题为“Bean 提供者的责任”的小节中。
关于Servlet 3.0规范,相关细节可以在第15.5节中找到.4 讨论了 servlet 容器的@Resource 注释语义。
JSR-250 (Common Annotations for the Java platform) addresses the runtime behavior of a container when processing classes with the
@Resource
annotation; the relevant section is 2.3, which discusses the@Resource
annotation.By and large, any resource that can be present in a deployment descriptor as a
env-entry
,service-ref
,resource-ref
,message-destination-ref
or aresource-env-ref
can be annotated with@Resource
annotation for injection. The list of specific Java types whose instances can be injected into supported classes is also specified in the same section, and is reproduced below:Note the last item in the table - according to the specification, any administered object associated with a resource, that is present in the JNDI directory can be injected.
A definite list of such classes whose instances must be injected by a container, can be obtained from Chapter 5 of the Java EE 6 Platform Specification. This is not tabulated in any form, but nevertheless, the chapter specifies how an application developer must request for injection of any significant resource. Most resources listed in the chapter are injected by specifying the
@Resource
annotation, or an another annotation that is used explicitly for that resource.The EJB 3.1 specification may repeat the contents of afore mentioned chapter 5 of the platform specification, for resources specific to the EJB container. The relevant details are in chapter 16 titled "Enterprise Bean Environment", with the relevant details being present in sub-sections titled "Bean Provider's Responsibilities".
With respect to the Servlet 3.0 Specification, the relevant details may be found in Section 15.5.4 which discusses the
@Resource
annotation semantics for a servlet container.