我在为几周前开始工作的项目的集成测试而苦苦挣扎的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-core”,“ spring-osgi-annotation”等)依赖于Spring Framework的版本“ 2.5.6”,而我已经使用版本“ 3.2.5”实现了.RELEASE”,但由于某些原因,旧版本仍在执行,如以下错误所示:
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)
有人知道为什么会这样吗?
非常感谢!
答案 0 :(得分:0)
您不应该自己包装所有捆绑包。有时制作OSGi捆绑软件比自动包装可以提供的更多。一个好的方法是检查Apache Karaf使用什么。
Spring和您需要的许多其他lib由服务组合包提供。
尝试一下:
Download and start Apache Karaf 4.1.5
feature:install spring hibernate transaction
la -s
因此,您会看到karaf在春季安装了哪些捆绑包。这些应该适合您的情况。
除此之外,如果您想使用OSGi,我真的会尝试摆脱春天。众所周知,Spring在OSGi中会引起很多问题,而新版本的兼容性甚至更低。
答案 1 :(得分:0)
我能够通过包装“ 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”依赖项不再要求“ org.springframework”库的较旧版本“ 2.5.6”。
现在,我面临着一个不同的问题,以使一切如另一个问题PAX EXAM Rest Endpoint not available for felix integration test所暴露。