Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Jersey 2.1 with CDI

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?

like image 321
siva636 Avatar asked Aug 12 '13 12:08

siva636


2 Answers

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.

like image 154
Chris Povirk Avatar answered Nov 05 '22 11:11

Chris Povirk


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.

like image 40
Bártfai Tamás Avatar answered Nov 05 '22 09:11

Bártfai Tamás