问题
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