Resource (Java EE 5)

Java EE API


javax.annotation Annotation Type Resource


@Target(value={TYPE,FIELD,METHOD})
@Retention(value=RUNTIME)
public @interface Resource

Implements: Annotation
@Target(value={TYPE, FIELD, METHOD})
@Retention(value=RUNTIME)

Resource 注释标记应用程序所需的资源。此注释可以应用于应用程序组件类,或者该组件类的字段或方法。如果将该注释应用于一个字段或方法,那么初始化应用程序组件时容器将把所请求资源的一个实例注入其中。如果将该注释应用于组件类,则该注释将声明一个应用程序在运行时将查找的资源。

即使此注释没有被标记为 Inherited,部署工具仍然需要检查任意组件类的所有超类,以发现这些超类中所有使用此注释的地方。所有此类注释实例都指定了应用程序组件所需的资源。注意,此注释可能出现在超类的 private 字段和方法上;在这种情况下容器也需要执行注入操作。

英文文档:

The Resource annotation marks a resource that is needed by the application. This annotation may be applied to an application component class, or to fields or methods of the component class. When the annotation is applied to a field or method, the container will inject an instance of the requested resource into the application component when the component is initialized. If the annotation is applied to the component class, the annotation declares a resource that the application will look up at runtime.

Even though this annotation is not marked Inherited, deployment tools are required to examine all superclasses of any component class to discover all uses of this annotation in all superclasses. All such annotation instances specify resources that are needed by the application component. Note that this annotation may appear on private fields and methods of superclasses; the container is required to perform injection in these cases as well.


Optional Element Summary
 Resource.AuthenticationType
 String
 String
 String
 boolean
 Class
 

abstract public String name()
资源的 JNDI 名称。对于字段注释,默认值为字段名称。对于方法注释,默认值为与该方法对应的 JavaBean 属性名称。对于类注释,没有默认值,必须指定此项。
英文文档:

name

public abstract String name
The JNDI name of the resource. For field annotations, the default is the field name. For method annotations, the default is the JavaBeans property name corresponding to the method. For class annotations, there is no default and this must be specified.

Default:
""

abstract public Class<T> type()
资源的 Java 类型。对于字段注释,默认值为字段的类型。对于方法注释,默认值为 JavaBean 属性的类型。对于类注释,没有默认值,必须指定此项。
英文文档:

type

public abstract Class type
The Java type of the resource. For field annotations, the default is the type of the field. For method annotations, the default is the type of the JavaBeans property. For class annotations, there is no default and this must be specified.

Default:
java.lang.Object.class

abstract public Resource.AuthenticationType authentication()
用于此资源的验证类型。可以为表示任何受支持类型的连接工厂的资源指定此方法,不得为其他类型的资源指定。
英文文档:

authentication

public abstract Resource.AuthenticationType authentication
The authentication type to use for this resource. This may be specified for resources representing a connection factory of any supported type, and must not be specified for resources of other types.

Default:
CONTAINER

abstract public boolean shareable()
指示是否能在此组件与其他组件之间共享此资源。可以为表示任何受支持类型的连接工厂的资源指定此方法,不得为其他类型的资源指定。
英文文档:

shareable

public abstract boolean shareable
Indicates whether this resource can be shared between this component and other components. This may be specified for resources representing a connection factory of any supported type, and must not be specified for resources of other types.

Default:
true

abstract public String mappedName()
此资源应该映射到的特定于产品的名称。此资源的名称(由 name 元素定义或为默认值)是使用该资源的应用程序组件的本地名称。(它的名称位于 JNDI java:comp/env 名称空间中。)许多应用程序服务器都提供一种方式将这些本地名称映射到应用程序服务器已知的资源名称。此映射的名称通常是全局 JNDI 名称,但也可以是任何形式的名称。

应用程序服务器不需要支持任何特殊形式或类型的映射名称,也不需要具有使用映射名称的能力。映射的名称与产品有关,并且通常与安装有关。任何对映射名称的使用都不可移植。

英文文档:

mappedName

public abstract String mappedName
A product specific name that this resource should be mapped to. The name of this resource, as defined by the name element or defaulted, is a name that is local to the application component using the resource. (It's a name in the JNDI java:comp/env namespace.) Many application servers provide a way to map these local names to names of resources known to the application server. This mapped name is often a global JNDI name, but may be a name of any form.

Application servers are not required to support any particular form or type of mapped name, nor the ability to use mapped names. The mapped name is product-dependent and often installation-dependent. No use of a mapped name is portable.

Default:
""

abstract public String description()
此资源的描述。描述应该使用部署应用程序的系统的默认语言。该描述能够呈现给部署者以帮助他们选择正确的资源。
英文文档:

description

public abstract String description
Description of this resource. The description is expected to be in the default language of the system on which the application is deployed. The description can be presented to the Deployer to help in choosing the correct resource.

Default:
""


Submit a bug or feature

Copyright 2007 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.

一看就知道只有菜鸟才干这么无知的事啦。

PS : 未经我党受权你也可自由散发此文档。 如有任何错误请自行修正;若因此而造成任何损失请直接找人民主席,请勿与本人联系。谢谢!