users@jersey.java.net

[Jersey] _at_Inject in custom validators (bean validation)

From: Jonas Oscarsson <jonas.osc_at_rsson.nu>
Date: Wed, 23 Oct 2013 20:21:30 +0200

Hi,

I have added a custom validation class implementing
ConstraintValidator<MyAnnotation, MyClassType>. I tried injecting some
dependencies into this class, but get the following exception:
*javax.validation.ValidationException:
HV000064: Unable to instantiate ConstraintValidator*.

Is perhaps not the validation framework integrated with the HK2 dependency
injection?

My other approach was then to try to get access to the ServiceLocator used
by Jersey to manually getService(TheClassINeed.class), but even though I
found a ServiceLocator on the ServiceLocatorFactory.getInstance() called
"jersey-server-rd-locator" it just returned null when using getService().

So, my two questions in short are:

   1. Is there any way to get the @Inject annotation to work on custom
   ConstraintValidator classes?
   2. Can I get hold of the Jersey HK2 ServiceLocator to manually inject
   the dependencies I need in my custom ConstraintValidator?

Thanks in advance! / Jonas