Resource (Common Annotations 3.0 API Documentation - Apache Tomcat 11.0.24)
Description: declaration: package: jakarta.annotation, annotation type: Resource

# Annotation Interface Resource

@Target({TYPE,FIELD,METHOD}) @Retention(RUNTIME) @Repeatable(Resources.class) public @interface Resource
Indicates a resource required by the application. Annotated classes will be used as resources. Annotated fields and/or methods will have resources injected.

Since:
  Common Annotations 1.0

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static enum`
  `Resource.AuthenticationType`
  The AuthenticationType, either CONTAINER or APPLICATION

- ## Optional Element Summary

  Optional Elements
  Modifier and Type
  Optional Element
  Description
  `Resource.AuthenticationType`
  `authenticationType`
  Specifies the authentication type for the resource.
  `String`
  `description`
  Provides a human-readable description of the resource for documentation and administrative purposes.
  `String`
  `lookup`
  Specifies the JNDI lookup name for the resource.
  `String`
  `mappedName`
  Specifies a product-dependent name for the resource, allowing the container to map the logical resource name to a physical resource in a vendor-specific manner.
  `String`
  `name`
  Specifies the logical name of the resource.
  `boolean`
  `shareable`
  Indicates whether the resource can be shared among multiple injection points.
  `Class<?>`
  `type`
  Uses generics since Common Annotations 1.2.

- ## Element Details

  - ### name

    String name
    Specifies the logical name of the resource. If not specified, the container derives the name from the field or method to which the annotation is applied.
    Returns:
      the logical name of the resource
    Default:
      `""`

  - ### type

    Class<?> type
    Uses generics since Common Annotations 1.2.
    Returns:
      The type for instances of this resource
    Default:
      `java.lang.Object.class`

  - ### authenticationType

    Resource.AuthenticationType authenticationType
    Specifies the authentication type for the resource. Container authentication means the container handles authentication, while application authentication means the application code is responsible for authentication.
    Returns:
      the authentication type, defaulting to `Resource.AuthenticationType.CONTAINER`
    Default:
      `CONTAINER`

  - ### shareable

    boolean shareable
    Indicates whether the resource can be shared among multiple injection points. When true, the same resource instance may be injected into multiple components. When false, each injection point receives a distinct resource instance.
    Returns:
      true if the resource is shareable across injection points, false otherwise
    Default:
      `true`

  - ### description

    String description
    Provides a human-readable description of the resource for documentation and administrative purposes.
    Returns:
      the resource description
    Default:
      `""`

  - ### mappedName

    String mappedName
    Specifies a product-dependent name for the resource, allowing the container to map the logical resource name to a physical resource in a vendor-specific manner. This is typically used for environment-specific configuration.
    Returns:
      the product-specific mapped name for the resource
    Default:
      `""`

  - ### lookup

    String lookup
    Specifies the JNDI lookup name for the resource. This attribute allows explicit control over the JNDI name used to locate the resource, overriding the default name derivation. The lookup name is typically prefixed with "java:comp/env/" for component environment entries.
    Returns:
      the JNDI lookup name for the resource
    Since:
      Common Annotations 1.1
    Default:
      `""`