JAXRS applications typically need context-based information to be obtained; this is made available by use of the @Context annotation. This information is available for all root resource classes and providers. Instances of an Application subclass can be used to store central configuration, and the same instance can then be accessed via @Context injection in resources or provider classes. We looked at UsersResource.add earlier, making use of , which was injected as a parameter. This instance can be injected into class fields or method parameters using @Context annotation. Similarly, there are other types that can be injected using this annotation, such as:
- Application
- UriInfo
- HttpHeaders
- Request
- SecurityContext
- Providers
- ResourceContext
- Configuration
It's also important to understand that the context is specific to a request.