On Oct 2, 2008, at 3:31 PM, Gili wrote:
>
> In other words, Spring can inject the fields just fine but later on
> when
> Jersey needs an instance some time later on it wouldn't know how to
> get it?
>
> This mechanism ensures that the instances are registered both with
> Jersey
> and with Spring?
>
Yes. Since Jersey is responsible for deploying those classes as
resource classes and invoking methods on them.
> So anyway, I'd need the same mechanism for Guice, right?
>
It is not absolutely necessary, but it improves the integration with
the IoC framework being used.
> I also don't understand why we need a separate "GuiceNamedInjectable
> implements InjectableProvider<Named, Type>". Why couldn't
> GuiceComponentProvider handle those as well?
>
Not for method parameters of methods that Jersey is responsible for
invoking, for example a resource method that needs access to some
Guice controlled instance:
@GET
public String get(@Named Foo foo) { ... }
Having an InjectableProvider allows for such functionality. Note that
Jersey will not inject onto fields whose values are non-null so it
should not overwrite what Guice has already injected.
BTW the general @Inject annotation supported by Jersey provides the
same behaviour independently of IoC framework, but it may be more
natural for Guice developers to use @Named. Again, it is not
absolutely necessary but improves the integration with Guice.
Paul.