Using Jersey 2.1 with CDI

痴心易碎 提交于 2019-12-10 13:30:33

问题


I try to use Jersey 2.1 and CDI in my Java EE 7 project which is deployed on Glassfish 4.0.

Jersey modules depend on Guava libraries. But using Guava libraries (14.0.1) with CDI results the following exception being thrown.

CDI deployment failure:WELD-001408 Unsatisfied dependencies for type [Set<Service>] with qualifiers [@Default] at injection point [[BackedAnnotatedParameter] Parameter 1 of [BackedAnnotatedConstructor] @Inject com.google.common.util.concurrent.ServiceManager(Set<Service>)].

How can I overcome this issue?


回答1:


CDI has some questionable behavior. We think we have two workarounds: one that you can do yourself and one that will work automatically when we release Guava 15.0. You can read more about the problem here.




回答2:


The problem here is that Guava classes are annotated, and CDI tries to inject dependencies into them.

The glassfish/modules directory contains a guava.jar. so simply setting the guava dependency to provided (or test) in maven solves the problem.



来源:https://stackoverflow.com/questions/18187137/using-jersey-2-1-with-cdi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!