users@jersey.java.net

[Jersey] CDI in filters and exception mappers

From: Pedro Nuno Santos <pedro-n-santos_at_ptinovacao.pt>
Date: Fri, 20 Dec 2013 10:55:25 +0000

Hi,

I'm not an expert on CDI (just learning the ropes) and I could be doing something wrong but shouldn't I be able to use @Inject inside filters and/or exception mappers?

I've tried both with glassfish 4.0 and 4.0.1 (using jersey 2.4.1) but injection only works inside resources. In both filters and exception mappers I get the following exception on deployment:

org.glassfish.hk2.api.UnsatisfiedDependencyException: There was no object available for injection at Injectee (...)

The only solution I found was to use AbstractBinder to register the classes to be injected, however that doesn't work if the object creation is being done using the @Produces annotation (I'm trying to inject a Logger instance and I need access to the class name where it's injected, from what I can gather the hk2 Factories don't allow me to access that information).

I remember once reading in the documentation that any class annotated with "@Provider" supported CDI but I can't seem to find the phrase anymore...


Cheers,
Pedro