eclipse-ee4j / eclipse-ee4j/jersey
Ambiguous dependencies injection when using the new CDI2
- Dominant language
- Java
- Stars
- 730
- Forks
- 382
- PR merge metrics
- No merged PRs in 30d
Description
Hi Jersey team,
using the new CDI2 bridge for jersey, I have this error :
```
org.jboss.weld.exceptions.DeploymentException: WELD-001409: Ambiguous dependencies for type HttpServletRequest with qualifiers @Default
at injection point [BackedAnnotatedField] @Inject org.glassfish.jersey.tests.integration.jersey2704.TestResource.request
at org.glassfish.jersey.tests.integration.jersey2704.TestResource.request(TestResource.java:0)
Possible dependencies:
- org.glassfish.jersey.inject.cdi.se.bean.SupplierBeanBridge@56820446,
- org.glassfish.jersey.inject.cdi.se.bean.SupplierBeanBridge@c14bbab
at org.jboss.weld.bootstrap.Validator.validateInjectionPointForDeploymentProblems(Validator.java:383)
at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:287)
at org.jboss.weld.bootstrap.Validator.validateGeneralBean(Validator.java:140)
at org.jboss.weld.bootstrap.Validator.validateCustomBean(Validator.java:195)
at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:520)
at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:63)
at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:61)
at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:62)
at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:55)
at java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1424)
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
```
Here a test case for it : https://github.com/hypnoce/jersey/commit/7e8a4c7b88c3e57946541335877b545791422905
The execution flow is the following :
- In [WebComponent.java#L330](https://github.com/jersey/jersey/blob/a9c0f9c62155b4300d1286f24d8a73cd4afb8b13/containers/jersey-servlet-core/src/main/java/org/glassfish/jersey/servlet/WebComponent.java#L330) a WebComponentBinder is registered into the resource config.
- This binder is then [passed to the ApplicationHandler](https://github.com/jersey/jersey/blob/a9c0f9c62155b4300d1286f24d8a73cd4afb8b13/containers/jersey-servlet-core/src/main/java/org/glassfish/jersey/servlet/WebComponent.java#L335) and is then [registered in the injectionmanager of the handler](https://github.com/jersey/jersey/blob/master/core-server/src/main/java/org/glassfish/jersey/server/ApplicationHandler.java#L289)
- At one point in time, the config binders (and therefore the one that [has been registered](https://github.com/jersey/jersey/blob/a9c0f9c62155b4300d1286f24d8a73cd4afb8b13/containers/jersey-servlet-core/src/main/java/org/glassfish/jersey/servlet/WebComponent.java#L330)) are [registered in the injection manager](https://github.com/jersey/jersey/blob/7c7a2893eea34d50047cbacbf759a68f18d5c7a8/core-common/src/main/java/org/glassfish/jersey/model/internal/CommonConfig.java#L647).
- At the end, [CdiSeInjectionManager#register](https://github.com/jersey/jersey/blob/b1dfab60e47b648db0d80e2035a96d8d26358819/inject/cdi2-se/src/main/java/org/glassfish/jersey/inject/cdi/se/CdiSeInjectionManager.java#L105) is called twice with the same exact binder.
Contributor guide
Assessment
This issue has not been assessed yet.