...
Apache Wink provides the @Scope annotation to specify the lifecycle of a provider or resource.
@Scope Annotation Specification
Value | Description | |
---|---|---|
Mandatory | No | |
Target | Provider class or Resource class | |
Parameters | Name | Type |
| Value | ScopeType enum |
Example | @Scope(ScopeType.PROTOTYPE) |
Resource Example
The following example illustrates how to define a resource with a singleton lifecycle.
Code Block | ||||
---|---|---|---|---|
| ||||
@Scope(ScopeType.SINGLETON)
@Path("service1")
public class ResourceA {
...
}
|
Provider Example
The following example illustrates how to define a provider with a prototype lifecycle.
Code Block | ||||
---|---|---|---|---|
| ||||
@Scope(ScopeType.PROTOTYPE)
@Provider
public class EntityProvider implements MessageBodyReader<String> {
...
}
|
@Parent Annotation
The @Parent annotation provides the ability to define a base template URI for the URI specified in a resources @Path annotation.
If a resource is annotated with the @Parent annotation, the Apache Wink runtime calculates the final resource template by first retrieving the value of the @Parent annotation, which holds the parent resource class, and then concatenates the resource path template definition to the path template definition of the parent resource.