[jax-rs-spec users] What is the standard behavior when injecting property on a singleton resource class?

From: Grant G Yang <>
Date: Mon, 21 Jul 2014 21:08:24 +0800

Dear experts,

When discussing the support of field / property injection, especially
@Context injection, the spec document seems lack of details on the part of
support singleton resource classes (either returned from
Application.getSingletons() or annotated with @Singleton).

1. The spec explicitly mentioned that for non-per-request resource classes,
support of field / property injection is not supported, but saying "with
the exception of @Context". However for @Context, there are also request
scope values (UriInfo, Request, HttpHeaders, SecurityContext) and non-scope
(Application, Providers, ResourceContext, Configuration) values. What is
the expected way to handle these very request scope values per spec?

2. How many times the injection shall be done to a singleton resource
class? I see in the latest javadoc of Application.getSingleton() saying "
Fields and properties of returned instances are injected with their
declared dependencies (see Context) by the runtime prior to use." While
"prior to use" is not a good way to describe the behavior, as "prior to use
on the first request" or "prior to use on every request". The
implementation shall inject the value only once or every time a request
comes by?

Actually when reading Jersey document I see Jersey already got some answer
of above questions, but not as part of spec; therefore I wanted to get
suggestions from you experts, on which part of complies to the spec, which
part shall belong to Jersey implementation specified (but of course can be
treated as best practice).

Any comments/suggestions will be more than welcome. Thanks in advance!

Software Architect, Websphere Development
IBM China Software Development Lab
Tel: 010 82451654