On May 2, 2010, at 9:42 PM, Morten wrote:
> I am trying to escape from all the trouble that Jersey has with
> integration with 3rd party dependency managers.
> In order escape to this simpler life, I am looking for an simple,
> universal method (if it exist?) of passing my own self-managed
> object instances from my application into jersey managed resources
> and providers that works with Java SE, OSGI, Java EE, Glassifsh 3.0
> out of the box (without using WELD/Guice/Spring or upgrading
> anything).
>
You can add singleton instances to the Application.
> The problem is that when Jersey creates the resources/providers I
> can't pass arguments to the constructor myself and all properties
> that I can define only accepts class names instead of pre-configured
> object instances which would solve the problem. Also, the build in
> @Context injection support in Jersey does unfortunately not allow me
> to inject my own objects which would also solve the problem.
You can register your own injectables by implementing:
https://jersey.dev.java.net/nonav/apidocs/latest/jersey/com/sun/jersey/spi/inject/InjectableProvider.html
> Finally, I did read somewhere that Jersey application objects can
> get injected but I don't always have such an object in use. F.x.
> does "GrizzlyServerFactory.create(uri, rc)" not have an overload
> that accepts a Jersey Application.
ResourceConfig extends from Application. You can use an instance of
DefaultResourceConfig if you wish.
Alternatively you can use the JAX-RS RuntimeDelegate.createEndpoint:
RuntimeDelegate.createEndpoint(app, Adapter.class)
then wire up Grizzly appropriately.
> And no, I can't setup a servlet context instead using ServletAdapter
> because then I will be affected by a bug in the Jersey-Weld-
> integration.
>
Is that the one i fixed related to class hierarchies?
You can also define your own component provider factory by
implementing IoCComponentProviderFactory that returns instances of
IoCManagedComponentProvider or IoCInstantiatedComponentProvider for
the classes you want to manage or construct.
Paul.
> The only solution I can currently see is to use global static
> variables to pass data between my application and jersey
> controllers. Not very nice or multi-thread safe?
>
> Other solutions?
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>