Package org.apache.sling.models.annotations.injectorspecific

# Annotation Interface SlingObject

@Target({METHOD,FIELD,PARAMETER}) @Retention(RUNTIME) @InjectAnnotation public @interface SlingObject
Injects common Sling objects that can be derived from either a SlingHttpServletRequest, a ResourceResolver or a Resource.

The injection is class-based.

Supports the following objects:
Class | Description | Request | ResourceResolver | Resource
--- | --- | --- | --- | ---
ResourceResolver | Resource resolver | X | X | X
Resource | Resource | X |  | X
SlingHttpServletRequest | Sling request | X |  |
SlingHttpServletResponse | Sling response | X |  |
SlingScriptHelper | Sling script helper | X |  |

## Optional Element Summary

Optional Elements
Modifier and Type
Optional Element
Description
`InjectionStrategy`
`injectionStrategy`
Specifies the injection strategy applied to an annotated element: If set to `InjectionStrategy.REQUIRED`, injection is mandatory. If set to `InjectionStrategy.OPTIONAL`, injection is optional. If set to `InjectionStrategy.DEFAULT` (default), the default injection strategy defined on the `Model` applies. WARNING: Injection strategy is ignored if either `Optional` or `Required` is applied on the same element.
`boolean`
`optional`
Deprecated.
Use `injectionStrategy()` instead

## Element Details

### optional

@Deprecated boolean optional
Deprecated.
Use `injectionStrategy()` instead
If set to true, the model can be instantiated even if there is no request attribute with the given name found. Default = false.

Returns:
  Optional

Default:
  false

### injectionStrategy

InjectionStrategy injectionStrategy
Specifies the injection strategy applied to an annotated element:

- If set to `InjectionStrategy.REQUIRED`, injection is mandatory.
- If set to `InjectionStrategy.OPTIONAL`, injection is optional.
- If set to `InjectionStrategy.DEFAULT` (default), the default injection strategy defined on the `Model` applies.

WARNING: Injection strategy is ignored if either `Optional` or `Required` is applied on the same element.

Returns:
  Injection strategy

Default:
  DEFAULT