我正在使用servicemix-4.4.1,

在我的pom.xml中,我定义了一个依赖项:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-validator</artifactId>
    <version>4.3.1.Final</version>
    <scope>provided</scope>
</dependency>


如您所见,我将范围设置为提供,因为servicemix(osgi容器)将为我们提供jar。

在我的features.xml文件中,我添加了:

<feature name="myapp-libs" version="${version}">
    ....
    <bundle>mvn:org.hibernate/hibernate-validator/4.3.1.Final/jar</bundle>


现在,当我尝试将myapp-libs加载到servicemix中时,得到以下信息:

karaf@root> features:install myapp-libs
Error executing command: Could not start bundle mvn:org.hibernate/hibernate-validator/4.3.1.Final/jar in feature(s)
myapp-libs-1.24-SNAPSHOT: Unresolved constraint in bundle org.hibernate.validator [973]:
Unable to resolve 973.0: missing requirement [973.0] package; (&(package=javax.validation)(version>=1.0.0)(!(version>=2.0.0)))

最佳答案

我在我的features.xml中定义了javax.validation,例如:

<bundle>mvn:javax.validation/validation-api/1.1.0.Final/jar</bundle>


但随后它不再找到hibernate-validator jar:

Add a provider like Hibernate Validator (RI) to your classpath.
javax.validation.ValidationException: Unable to create a Configuration, because no Bean Validation provider could be found. Add a provider like Hibernate Validator (RI) to your classpath.
at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:271)
at javax.validation.Validation.buildDefaultValidatorFactory(Validation.java:110)


这很奇怪,因为在日志中我可以看到正在加载hibernate-validator。

22:53:40,835 | INFO  | l Console Thread | FeaturesServiceImpl              | ?

    ? | 30 - org.apache.karaf.features.core - 2.2.2.fuse-07-11 | Installing bundle mvn:com.googlecode.guava-osgi/guava-osgi/9.0.0/jar
22:53:42,064 | INFO  | l Console Thread | FeaturesServiceImpl              | ?                                   ? | 30 - org.apache.karaf.features.core - 2.2.2.fuse-07-11 | Installing bundle mvn:commons-lang/commons-lang/2.6
22:53:42,203 | INFO  | l Console Thread | FeaturesServiceImpl              | ?                                   ? | 30 - org.apache.karaf.features.core - 2.2.2.fuse-07-11 | Installing bundle wrap:mvn:junit/junit/4.11/jar
22:53:42,312 | INFO  | l Console Thread | FeaturesServiceImpl              | ?                                   ? | 30 - org.apache.karaf.features.core - 2.2.2.fuse-07-11 | Installing bundle wrap:mvn:org.apache.thrift/libthrift/0.7.0/jar
22:53:42,441 | INFO  | l Console Thread | FeaturesServiceImpl              | ?                                   ? | 30 - org.apache.karaf.features.core - 2.2.2.fuse-07-11 | Installing bundle wrap:mvn:org.apache.cassandra/cassandra-thrift/1.1.0/jar
22:53:42,625 | INFO  | l Console Thread | FeaturesServiceImpl              | ?                                   ? | 30 - org.apache.karaf.features.core - 2.2.2.fuse-07-11 | Installing bundle mvn:org.hectorclient/hector-core/1.1-2/jar
22:53:42,836 | INFO  | l Console Thread | FeaturesServiceImpl              | ?                                   ? | 30 - org.apache.karaf.features.core - 2.2.2.fuse-07-11 | Installing bundle mvn:org.codehaus.jackson/jackson-core-asl/1.9.6/jar
22:53:43,396 | INFO  | l Console Thread | FeaturesServiceImpl              | ?                                   ? | 30 - org.apache.karaf.features.core - 2.2.2.fuse-07-11 | Installing bundle mvn:org.codehaus.jackson/jackson-mapper-asl/1.9.6/jar
22:53:44,396 | INFO  | l Console Thread | FeaturesServiceImpl              | ?                                   ? | 30 - org.apache.karaf.features.core - 2.2.2.fuse-07-11 | Installing bundle mvn:org.codehaus.jackson/jackson-jaxrs/1.9.6/jar
22:53:44,416 | INFO  | l Console Thread | FeaturesServiceImpl              | ?                                   ? | 30 - org.apache.karaf.features.core - 2.2.2.fuse-07-11 | Installing bundle mvn:org.hibernate/hibernate-validator/4.1.0.Final/jar
22:53:44,425 | INFO  | l Console Thread | FeaturesServiceImpl              | ?                                   ? | 30 - org.apache.karaf.features.core - 2.2.2.fuse-07-11 | Installing bundle mvn:javax.validation/validation-api/1.1.0.Final/jar
22:53:44,459 | INFO  | l Console Thread | FeaturesServiceImpl              | ?                                   ? | 30 - org.apache.karaf.features.core - 2.2.2.fuse-07-11 | Installing bundle mvn:org.apache.camel/camel-jackson/2.8.0/jar
22:53:44,467 | INFO  | l Console Thread | FeaturesServiceImpl              | ?                                   ? | 30 - org.apache.karaf.features.core - 2.2.2.fuse-07-11 | Installing bundle mvn:joda-time/joda-time/1.6
22:53:44,780 | INFO  | l Console Thread | FeaturesServiceImpl              | ?                                   ? | 30 - org.apache.karaf.features.core - 2.2.2.fuse-07-11 | Installing bundle wrap:mvn:org.perf4j/perf4j/0.9.16/jar
22:53:45,061 | INFO  | l Console Thread | FeaturesServiceImpl              | ?                                   ? | 30 - org.apache.karaf.features.core - 2.2.2.fuse-07-11 | Installing bundle wrap:mvn:org.aspectj/aspectjrt/1.6.1/jar
22:53:46,600 | INFO  | l Console Thread | FeaturesServiceImpl              | ?                                   ? | 30 - org.apache.karaf.features.core - 2.2.2.fuse-07-11 | Installing bundle wrap:mvn:org.aspectj/aspectjweaver/1.6.1/jar
22:53:46,867 | INFO  | l Console Thread | FeaturesServiceImpl              | ?                                   ? | 30 - org.apache.karaf.features.core - 2.2.2.fuse-07-11 | Installing bundle wrap:mvn:commons-jexl/commons-jexl/1.1/jar
22:53:46,893 | INFO  | l Console Thread | FeaturesServiceImpl              | ?                                   ? | 30 - org.apache.karaf.features.core - 2.2.2.fuse-07-11 | Installing bundle wrap:mvn:com.eaio.uuid/uuid/3.2/jar
22:53:46,899 | INFO  | l Console Thread | FeaturesServiceImpl              | ?                                   ? | 30 - org.apache.karaf.features.core - 2.2.2.fuse-07-11 | Bundles to refresh:

09-29 21:58