PAM EXAM配置依赖项要求在较新的JAR可用时使用较旧的JAR



我正在为几周前开始工作的一个项目的集成测试进行PAX EXAM配置。

主要的问题是关于我打算测试的捆绑包的依赖性,但我总是能够针对每个问题进行改进,但现在我真的陷入了困境。

下面我列出了我的@Configuration方法的当前版本:

@Configuration
public Option[] configure() {
// Runs outside the OSGi framework
return options(
junitBundles(),
wrappedBundle( mavenBundle( "antlr", "antlr" ).version( "2.7.7" ) ),
wrappedBundle( mavenBundle( "com.fasterxml", "classmate" ).version( "1.3.0" ) ),
wrappedBundle( mavenBundle( "org.javassist", "javassist" ).version( "3.18.1-GA" ) ),
wrappedBundle( mavenBundle( "org.jboss.logging", "jboss-logging" ).version( "3.1.0.GA" ) ),
wrappedBundle( mavenBundle( "dom4j", "dom4j" ).version( "1.6.1" ) ),
//wrappedBundle( mavenBundle( "org.hibernate.javax.persistence", "hibernate-jpa-2.0-api" ).version( "1.0.1.Final" ) ),
mavenBundle( "javax.persistence", "com.springsource.javax.persistence" ).version( "2.0.0" ),
wrappedBundle( mavenBundle( "org.jboss.spec.javax.transaction", "jboss-transaction-api_1.1_spec" ).version( "1.0.1.Final" ) ),
//wrappedBundle( mavenBundle( "javax.transaction", "javax.transaction-api" ).version( "1.2" ) ),
//wrappedBundle( mavenBundle( "javax.enterprise", "cdi-api" ).version( "1.0-SP4" ) ),
//wrappedBundle( mavenBundle( "org.jboss.spec.javax.interceptor", "jboss-interceptors-api_1.1_spec" ).version( "1.0.0.Beta1" ) ),
wrappedBundle( mavenBundle( "org.jboss", "jandex" ).version( "1.0.3.Final" ) ),
wrappedBundle( mavenBundle( "org.hibernate", "hibernate-core" ).version( "4.2.21.Final" ) ),
wrappedBundle( mavenBundle( "org.springframework", "spring-beans" ).version( "3.2.5.RELEASE" ) ).bundleSymbolicName( "org.springframework.beans" ).bundleVersion( "3.2.5.RELEASE" ),
wrappedBundle( mavenBundle( "org.springframework", "spring-context" ).version( "3.2.5.RELEASE" ) ).bundleSymbolicName( "org.springframework.context" ).bundleVersion( "3.2.5.RELEASE" ),
wrappedBundle( mavenBundle( "org.springframework", "spring-core" ).version( "3.2.5.RELEASE" ) ).bundleSymbolicName( "org.springframework.core" ).bundleVersion( "3.2.5.RELEASE" ),
wrappedBundle( mavenBundle( "org.springframework", "spring-aop" ).version( "3.2.5.RELEASE" ) ).bundleSymbolicName( "org.springframework.aop" ).bundleVersion( "3.2.5.RELEASE" ),
wrappedBundle( mavenBundle( "org.springframework", "spring-jdbc" ).version( "3.2.5.RELEASE" ) ).bundleSymbolicName( "org.springframework.jdbc" ).bundleVersion( "3.2.5.RELEASE" ),
wrappedBundle( mavenBundle( "org.springframework", "spring-tx" ).version( "3.2.5.RELEASE" ) ).bundleSymbolicName( "org.springframework.tx" ).bundleVersion( "3.2.5.RELEASE" ),
wrappedBundle( mavenBundle( "aopalliance", "aopalliance" ).version( "1.0" ) ),
wrappedBundle( mavenBundle( "org.springframework.osgi", "spring-osgi-core" ).version( "1.2.1" ) ),
wrappedBundle( mavenBundle( "org.springframework.osgi", "spring-osgi-annotation" ).version( "1.2.1" ) ),
wrappedBundle( mavenBundle( "org.springframework.osgi", "spring-osgi-extender" ).version( "1.2.1" ) ),
wrappedBundle( mavenBundle( "commons-lang", "commons-lang" ).version( "2.6" ) ),
wrappedBundle( mavenBundle( "org.hibernate.common", "hibernate-commons-annotations" ).version( "4.0.2.Final" ) );
}

我删除了我们的业务依赖关系,因为它们对于解释来说是不必要的。

Spring OSGI依赖项("Spring-OSGI核心"、"Spring-OSGI注释"等(依赖于Spring Framework的"2.5.6"版本,我已经用这些库的"3.2.5.REASE"版本实现了这一点,但由于某些原因,旧版本仍在强制执行,如下错误所示:

org.osgi.framework.BundleException: Unable to resolve br.com.mycompany.myapplication.osgi.entity.interceptor.entity-interceptor [39](R 39.0): missing requirement [br.com.mycompany.myapplication.osgi.entity.interceptor.entity-interceptor [39](R 39.0)] osgi.wiring.package; (&(osgi.wiring.package=org.springframework.osgi.extensions.annotation)(version>=1.2.0)) [caused by: Unable to resolve org.springframework.osgi.extensions.annotations [33](R 33.0): missing requirement [org.springframework.osgi.extensions.annotations [33](R 33.0)] osgi.wiring.package; (&(osgi.wiring.package=org.springframework.beans)(version>=2.5.6)(!(version>=4.0.0)))] Unresolved requirements: [[br.com.mycompany.myapplication.osgi.entity.interceptor.entity-interceptor [39](R 39.0)] osgi.wiring.package; (&(osgi.wiring.package=org.springframework.osgi.extensions.annotation)(version>=1.2.0))]
at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:4111)
at org.apache.felix.framework.Felix.startBundle(Felix.java:2117)
at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1371)
at org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStartLevelImpl.java:308)
at java.lang.Thread.run(Thread.java:748)
org.osgi.framework.BundleException: Unable to resolve br.com.mycompany.myapplication.api.log.application-log-service [40](R 40.0): missing requirement [br.com.mycompany.myapplication.api.log.application-log-service [40](R 40.0)] osgi.wiring.package; (osgi.wiring.package=br.com.mycompany.myapplication.osgi.entity.interceptor.repository) [caused by: Unable to resolve br.com.mycompany.myapplication.osgi.entity.interceptor.entity-interceptor [39](R 39.0): missing requirement [br.com.mycompany.myapplication.osgi.entity.interceptor.entity-interceptor [39](R 39.0)] osgi.wiring.package; (&(osgi.wiring.package=org.springframework.osgi.extensions.annotation)(version>=1.2.0)) [caused by: Unable to resolve org.springframework.osgi.extensions.annotations [33](R 33.0): missing requirement [org.springframework.osgi.extensions.annotations [33](R 33.0)] osgi.wiring.package; (&(osgi.wiring.package=org.springframework.beans)(version>=2.5.6)(!(version>=4.0.0)))]] Unresolved requirements: [[br.com.mycompany.myapplication.api.log.application-log-service [40](R 40.0)] osgi.wiring.package; (osgi.wiring.package=br.com.mycompany.myapplication.osgi.entity.interceptor.repository)]
at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:4111)
at org.apache.felix.framework.Felix.startBundle(Felix.java:2117)
at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1371)
at org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStartLevelImpl.java:308)
at java.lang.Thread.run(Thread.java:748)
ERROR: Bundle br.com.mycompany.myapplication.api.log.application-log-service [40] Error starting file:/tmp/1533155354575-0/pax-exam-downloads/br.com.mycompany.myapplication.api.log.application-log-service_1.46.0.SNAPSHOT.jar (org.osgi.framework.BundleException: Unable to resolve br.com.mycompany.myapplication.api.log.application-log-service [40](R 40.0): missing requirement [br.com.mycompany.myapplication.api.log.application-log-service [40](R 40.0)] osgi.wiring.package; (osgi.wiring.package=br.com.mycompany.myapplication.osgi.entity.interceptor.repository) [caused by: Unable to resolve br.com.mycompany.myapplication.osgi.entity.interceptor.entity-interceptor [39](R 39.0): missing requirement [br.com.mycompany.myapplication.osgi.entity.interceptor.entity-interceptor [39](R 39.0)] osgi.wiring.package; (&(osgi.wiring.package=org.springframework.osgi.extensions.annotation)(version>=1.2.0)) [caused by: Unable to resolve org.springframework.osgi.extensions.annotations [33](R 33.0): missing requirement [org.springframework.osgi.extensions.annotations [33](R 33.0)] osgi.wiring.package; (&(osgi.wiring.package=org.springframework.beans)(version>=2.5.6)(!(version>=4.0.0)))]] Unresolved requirements: [[br.com.mycompany.myapplication.api.log.application-log-service [40](R 40.0)] osgi.wiring.package; (osgi.wiring.package=br.com.mycompany.myapplication.osgi.entity.interceptor.repository)])
org.osgi.framework.BundleException: Unable to resolve br.com.mycompany.myapplication.api.log.listener.application-log-listener [41](R 41.0): missing requirement [br.com.mycompany.myapplication.api.log.listener.application-log-listener [41](R 41.0)] osgi.wiring.package; (osgi.wiring.package=br.com.mycompany.idpclient.model) Unresolved requirements: [[br.com.mycompany.myapplication.api.log.listener.application-log-listener [41](R 41.0)] osgi.wiring.package; (osgi.wiring.package=br.com.mycompany.idpclient.model)]
at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:4111)
at org.apache.felix.framework.Felix.startBundle(Felix.java:2117)
at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1371)
at org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStartLevelImpl.java:308)
at java.lang.Thread.run(Thread.java:748)

有人知道为什么会发生这种事吗?

非常感谢并致以最良好的问候!

您不应该自己包装所有捆绑包。有时,制作OSGi捆绑包需要的东西比自动包装所能提供的还要多。一个好的方法是检查ApacheKaraf使用了什么。

Spring和您需要的许多其他库都是由服务混合包提供的。

试试这个:

Download and start Apache Karaf 4.1.5
feature:install spring hibernate transaction
la -s

所以你可以看到karaf为春季安装了什么捆绑包。这些应该更适合你的情况。

除此之外,如果你想使用OSGi,我真的会尽量远离spring。众所周知,Spring会在OSGi中引发很多问题,而新版本的兼容性甚至更低。

我能够通过包装"org.springframework"依赖项来解决这个问题,以便更改它们的清单,如下所示:

wrappedBundle( mavenBundle( "org.springframework", "spring-beans" ).version( "3.2.5.RELEASE" ) ).bundleSymbolicName( "org.springframework.beans" ).bundleVersion( "3.2.5.RELEASE" )
.exports( "*;version=3.2.5.RELEASE" ).overwriteManifest( WrappedUrlProvisionOption.OverwriteMode.MERGE ),
wrappedBundle( mavenBundle( "org.springframework", "spring-core" ).version( "3.2.5.RELEASE" ) ).bundleSymbolicName( "org.springframework.core" ).bundleVersion( "3.2.5.RELEASE" )
.exports( "*;version=3.2.5.RELEASE" ).overwriteManifest( WrappedUrlProvisionOption.OverwriteMode.MERGE ),
wrappedBundle( mavenBundle( "org.springframework", "spring-context" ).version( "3.2.5.RELEASE" ) ).bundleSymbolicName( "org.springframework.context" ).bundleVersion( "3.2.5.RELEASE" )
.exports( "*;version=3.2.5.RELEASE" ).overwriteManifest( WrappedUrlProvisionOption.OverwriteMode.MERGE ),
wrappedBundle( mavenBundle( "org.springframework", "spring-jdbc" ).version( "3.2.5.RELEASE" ) ).bundleSymbolicName( "org.springframework.jdbc" ).bundleVersion( "3.2.5.RELEASE" )
.exports( "*;version=3.2.5.RELEASE" ).overwriteManifest( WrappedUrlProvisionOption.OverwriteMode.MERGE ),
wrappedBundle( mavenBundle( "org.springframework", "spring-aop" ).version( "3.2.5.RELEASE" ) ).bundleSymbolicName( "org.springframework.aop" ).bundleVersion( "3.2.5.RELEASE" )
.exports( "*;version=3.2.5.RELEASE" ).overwriteManifest( WrappedUrlProvisionOption.OverwriteMode.MERGE ),
wrappedBundle( mavenBundle( "org.springframework", "spring-orm" ).version( "3.2.5.RELEASE" ) ).bundleSymbolicName( "org.springframework.orm" ).bundleVersion( "3.2.5.RELEASE" )
.exports( "*;version=3.2.5.RELEASE" ).overwriteManifest( WrappedUrlProvisionOption.OverwriteMode.MERGE ),
wrappedBundle( mavenBundle( "org.springframework", "spring-tx" ).version( "3.2.5.RELEASE" ) ).bundleSymbolicName( "org.springframework.transaction" ).bundleVersion( "3.2.5.RELEASE" )
.exports( "*;version=3.2.5.RELEASE" ).overwriteManifest( WrappedUrlProvisionOption.OverwriteMode.MERGE ),

有了这个变化,"org.springframework.osgi"依赖项就不再需要旧的"2.5.6"版本的"org.springframework"libs了。

现在,我面临着另一个问题:PAX EXAM Rest Endpoint不可用于felix集成测试。