You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@servicemix.apache.org by Benson Margulies <be...@basistech.com> on 2015/10/24 04:19:59 UTC

Troubles with class loading with jsr 303.

I have a pax-exam test of code that uses Apache bval and thus
javax.validation, and I use the servicemix spec provider.

The test fails with java.lang.ClassCastException:
org.apache.bval.jsr.ApacheValidationProvider cannot be cast to
javax.validation.spi.ValidationProvider.

When I stop it in the debugger, I see that there are indeed two Class
objects afloat for ValidationProvider.

One of them is a sun.misc.Launcher$AppClassLoader. The other is an
OSGi class loader.

The sun.misc one is the one for the interface of the class returned by ...

Class<? extends ValidationProvider> providerClass =
org.apache.servicemix.specs.locator.OsgiLocator.locate(ValidationProvider.class);

Re: Troubles with class loading with jsr 303.

Posted by Łukasz Dywicki <lu...@code-house.org>.
You may use javax.validation.ValidationProvider class directly to lookup spec implementation, if you have geronimo-osgi-locator bundle installed. Geronimo locator is installed by default in karaf. I was using bval a lot in our tests. You can check this repo - it does work with karaf 3.0.4, but 2.x is pretty much the same:

https://github.com/Code-House/karaf-validation <https://github.com/Code-House/karaf-validation>

Kind regards,
Lukasz
—
luke@code-house.org
Twitter: ldywicki
Blog: http://dywicki.pl
Code-House - http://code-house.org


> Wiadomość napisana przez Benson Margulies <be...@basistech.com> w dniu 23 paź 2015, o godz. 22:19:
> 
> I have a pax-exam test of code that uses Apache bval and thus
> javax.validation, and I use the servicemix spec provider.
> 
> The test fails with java.lang.ClassCastException:
> org.apache.bval.jsr.ApacheValidationProvider cannot be cast to
> javax.validation.spi.ValidationProvider.
> 
> When I stop it in the debugger, I see that there are indeed two Class
> objects afloat for ValidationProvider.
> 
> One of them is a sun.misc.Launcher$AppClassLoader. The other is an
> OSGi class loader.
> 
> The sun.misc one is the one for the interface of the class returned by ...
> 
> Class<? extends ValidationProvider> providerClass =
> org.apache.servicemix.specs.locator.OsgiLocator.locate(ValidationProvider.class);


Re: Troubles with class loading with jsr 303.

Posted by Benson Margulies <bi...@gmail.com>.
I had to set the context class loader.

On Fri, Oct 23, 2015 at 10:19 PM, Benson Margulies <be...@basistech.com> wrote:
> I have a pax-exam test of code that uses Apache bval and thus
> javax.validation, and I use the servicemix spec provider.
>
> The test fails with java.lang.ClassCastException:
> org.apache.bval.jsr.ApacheValidationProvider cannot be cast to
> javax.validation.spi.ValidationProvider.
>
> When I stop it in the debugger, I see that there are indeed two Class
> objects afloat for ValidationProvider.
>
> One of them is a sun.misc.Launcher$AppClassLoader. The other is an
> OSGi class loader.
>
> The sun.misc one is the one for the interface of the class returned by ...
>
> Class<? extends ValidationProvider> providerClass =
> org.apache.servicemix.specs.locator.OsgiLocator.locate(ValidationProvider.class);