eclipse-ee4j / eclipse-ee4j/jersey
Jetty + Weld + Jersey: no object available for injection
- Dominant language
- Java
- Stars
- 730
- Forks
- 382
- PR merge metrics
- No merged PRs in 30d
Description
I would like to `@Inject` some bean into a JAX-RS resource using Weld.
Jetty is configured to interact with Weld, and this works: I can inject beans (and even use `@Transactional` services) into a normal servlet.
But when injecting into a JAX-RS resource, HK2 tells me: `org.glassfish.hk2.api.UnsatisfiedDependencyException: There was no object available for injection`.
Following the instructions [here](https://github.com/eclipse-ee4j/jersey/issues/4121), I do not depend on `org.glassfish.jersey.ext.cdi:jersey-weld2-se`, but I do depend on `org.glassfish.jersey.inject:jersey-hk2`.
Related question: how is HK2 supposed to know that it must delegate injection to Weld? I did not tell anthing about Weld to Jersey. I suspect this explains the failure.
Is there an example I could use to check for differences? (I have looked at the [helloworld-cdi2-se](https://github.com/eclipse-ee4j/jersey/blob/master/examples/helloworld-cdi2-se) and [cdi-webapp](https://github.com/eclipse-ee4j/jersey/blob/master/examples/cdi-webapp) examples but they do not seem to let HK2 interact with Weld.)
You may checkout [this commit](https://github.com/oliviercailloux/sample-jetty/tree/8359d0f7152d3d3aec09e3387c5098cf1a80fa2b) to reproduce the problem.
Thanks for any pointer.
Contributor guide
Assessment
This issue has not been assessed yet.