Hi,
Craig wrote:
> Stephan Koops wrote:
> > Hi,
> >
> > what's the problem to inject in @*Param and @Context annotated fields
> > and bean setters, also if the object is not instantiated by the runtime?
> > If it shouldn't be injected, than IMO the developer mjst not annotate
> > field / bean setters.
> >
> One key issue is that the JAX-RS runtime does not know that the
> sub-resource instance got instantiated at all, because it cannot plug
> directly into the "new" operator of the JVM. This is the same reason
> that, in all the cases where resource injection is defined in Java EE 5,
> it only works in container-managed objects.
>
> A second major problem, as Marc and Paul have mentioned, is that the
> runtime would have no way to understand the lifecycle of the
> instantiated object, and therefore no way to understand when a previous
> injection might not be thread safe, or might no longer be valid.
If the sub resource instance is a singelton, the annotations @*Params are
nonsense and should not be used. So there are only @Context annotated fields
and bean setters. And they must be accessible by multiple threads at the same
time. So the injected object could ever be the same, that is already injected,
and there is also no problem.
best regards
Stephan