I'm using the servicemix packaging of hibernate-validator and jsr303:

*    <dependency>*
*      <groupId>org.apache.servicemix.specs</groupId>*
*      <artifactId>org.apache.servicemix.specs.jsr303-api-1.0.0</artifactId>
*
*      <version>1.5.0</version>*
*    </dependency>*
*
*
*    <dependency>*
*      <groupId>org.apache.servicemix.bundles</groupId>*
*
 <artifactId>org.apache.servicemix.bundles.hibernate-validator</artifactId>*
*      <version>4.1.0.Final_1</version>*
*    </dependency>*

I use the validator "manually" (not automatically via JPA) as follows:
*
*

> *public static Set<ConstraintViolation<?>> violations(Object theObject,
> Class<?>... theGroups)*

*      throws ConstraintViolationException {*

*    /**

*     * Perform bean validation*

*     */*

*    ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
> // Throws exception*

*    Validator validator = factory.getValidator();*

*    return (Set) validator.validate(theObject, theGroups);*

*  }*


 The line that creates the ValidatorFactory throws an exception when called
from wihin OSGi:

javax.validation.ValidationException: Unable to find a default provider

at
> javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:264)

at
> javax.validation.Validation.buildDefaultValidatorFactory(Validation.java:111)

at validator.test1.impl.ServiceOne.createEntityOne(ServiceOne.java:17)

at validator.test.itest.OsgiTest.createTest(OsgiTest.java:29)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:597)

at
> org.ops4j.pax.exam.junit.extender.impl.internal.CallableTestMethodImpl.injectContextAndInvoke(CallableTestMethodImpl.java:143)

at
> org.ops4j.pax.exam.junit.extender.impl.internal.CallableTestMethodImpl.call(CallableTestMethodImpl.java:105)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:597)

at
> org.ops4j.pax.exam.rbc.internal.RemoteBundleContextImpl.remoteCall(RemoteBundleContextImpl.java:80)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:597)

at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:305)

at sun.rmi.transport.Transport$1.run(Transport.java:159)

at java.security.AccessController.doPrivileged(Native Method)

at sun.rmi.transport.Transport.serviceCall(Transport.java:155)

at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)

at
> sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)

at
> sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)

at
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)

at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)

at java.lang.Thread.run(Thread.java:619)


When I run the same code outside of OSGi everything works. What am I doing
wrong?

The test above used Pax-Exam with Felix 3.0.2 but it doesn't seem to matter
what OSGi container I use. I've tried different versions of Felix and
Equinox but I get the same exception. I suspect I'm doing something wrong
but I cannot see what. Can someone help me out?

/Bengt

Reply via email to