如何使用OSGi容器启用ApacheTuscany SDO?[类加载器问题]

如何使用OSGi容器启用ApacheTuscany SDO?[类加载器问题],osgi,classloader,apache-servicemix,sdo,apache-tuscany,Osgi,Classloader,Apache Servicemix,Sdo,Apache Tuscany,我尝试在ApacheServiceMix和SDO中使用ApacheCXF。SDO随Apache Tuscany SDO实现一起提供 以下是依赖关系图: 我的osgi包公开了一个web服务,该包依赖于SDO CXF系统包也依赖于SDO 我安装了Apache Tuscany SDO捆绑包堆栈,如下所示: osgi:install -s mvn:org.apache.tuscany.sdo/tuscany-sdo-api-r2.1/1.1.1 osgi:install -s mvn:org.apach

我尝试在ApacheServiceMix和SDO中使用ApacheCXF。SDO随Apache Tuscany SDO实现一起提供

以下是依赖关系图:

我的osgi包公开了一个web服务,该包依赖于SDO

CXF系统包也依赖于SDO

我安装了Apache Tuscany SDO捆绑包堆栈,如下所示:

osgi:install -s mvn:org.apache.tuscany.sdo/tuscany-sdo-api-r2.1/1.1.1
osgi:install -s mvn:org.apache.tuscany.sdo/tuscany-sdo-impl/1.1.1
osgi:install -s mvn:org.apache.tuscany.sdo/tuscany-sdo-lib/1.1.1
osgi:install -s mvn:org.apache.tuscany.sdo/tuscany-sdo-tools/1.1.1
起始级别为:

...
tuscany-sdo-api-r2.1              28
tuscany-sdo-impl                  28
tuscany-sdo-lib                   28
tuscany-sdo-tools                 28

Apache CXF Bundle Jar (2.4.6)     30
camel-cxf (2.8.5)                 50
camel-cxf-transport (2.8.5)       50
...
MyApplication                     60
重新启动服务器时,会打印以下异常:

karaf@root> Exception in thread "SpringOsgiExtenderThread-4" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'iws': Invocation of init method failed; nested exception is java.lang.ExceptionInInitializerError
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
        at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.access$1600(AbstractDelegatedExecutionApplicationContext.java:69)
        at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext$4.run(AbstractDelegatedExecutionApplicationContext.java:355)
        at org.springframework.osgi.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85)
        at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(AbstractDelegatedExecutionApplicationContext.java:320)
        at org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$CompleteRefreshTask.run(DependencyWaiterApplicationContextExecutor.java:132)
        at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.ExceptionInInitializerError
        at org.apache.cxf.sdo.SDODataBinding.initialize(SDODataBinding.java:128)
        at org.apache.cxf.service.factory.AbstractServiceFactoryBean.initializeDataBindings(AbstractServiceFactoryBean.java:86)
        at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.buildServiceFromClass(ReflectionServiceFactoryBean.java:444)
        at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.buildServiceFromClass(JaxWsServiceFactoryBean.java:685)
        at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.initializeServiceModel(ReflectionServiceFactoryBean.java:507)
        at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.create(ReflectionServiceFactoryBean.java:241)
        at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.create(JaxWsServiceFactoryBean.java:205)
        at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint(AbstractWSDLBasedEndpointFactory.java:101)
        at org.apache.cxf.frontend.ServerFactoryBean.create(ServerFactoryBean.java:157)
        at org.apache.cxf.jaxws.JaxWsServerFactoryBean.create(JaxWsServerFactoryBean.java:203)
        at org.apache.cxf.jaxws.EndpointImpl.getServer(EndpointImpl.java:433)
        at org.apache.cxf.jaxws.EndpointImpl.doPublish(EndpointImpl.java:322)
        at org.apache.cxf.jaxws.EndpointImpl.publish(EndpointImpl.java:239)
        at org.apache.cxf.jaxws.EndpointImpl.publish(EndpointImpl.java:509)
        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.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1544)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1485)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
        ... 14 more
Caused by: java.lang.NullPointerException
        at org.apache.tuscany.sdo.api.SDOUtil.<clinit>(SDOUtil.java:48)
        ... 35 more
tuscany-sdo-api-r2.1中的SDOUtil类依赖于帮助器类commonj.sdo.impl.HelperProvider.java

HelperProvider.java()的源代码

这意味着getInstance()方法无法正常工作

如何使SDOHelper在包含的OSGi中正确初始化?

更新

pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <!-- Generated by Apache ServiceMix Archetype -->

    <modelVersion>4.0.0</modelVersion>

    <groupId>com.bssys</groupId>
    <artifactId>eg-smx-osgi-bundle</artifactId>
    <packaging>bundle</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>Apache ServiceMix :: Camel OSGi Bundle</name>

    <properties>
       <camel.version>2.8.3</camel.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-core</artifactId>
            <version>${camel.version}</version>
        </dependency>

        <!-- CXF SDO -->
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-databinding-sdo</artifactId>
            <version>2.4.6</version>
        </dependency>

        <!-- Apache tuscany SDO -->
        <dependency>
            <groupId>org.apache.tuscany.sdo</groupId>
            <artifactId>tuscany-sdo-api-r2.1</artifactId>
            <version>1.1.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tuscany.sdo</groupId>
            <artifactId>tuscany-sdo-impl</artifactId>
            <version>1.1.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tuscany.sdo</groupId>
            <artifactId>tuscany-sdo-lib</artifactId>
            <version>1.1.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tuscany.sdo</groupId>
            <artifactId>tuscany-sdo-tools</artifactId>
            <version>1.1.1</version>
        </dependency>

    </dependencies>

    <build>
        <defaultGoal>install</defaultGoal>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.0.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.4.3</version>
                <configuration>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <version>2.3.6</version>
                <extensions>true</extensions>
                <configuration>
                    <instructions>
                        <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
                        <Import-Package>*,org.apache.camel.osgi</Import-Package>
                        <Private-Package>com.bssys</Private-Package>
                    </instructions>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

4.0.0
com.bssys
eg smx osgi束
捆
1.0-快照
ApacheServiceMix::驼峰OSGi包
2.8.3
org.apache.camel
驼芯
${camel.version}
org.apache.cxf
cxf rt数据绑定sdo
2.4.6
org.apache.tuscany.sdo
托斯卡纳-sdo-api-r2.1
1.1.1
org.apache.tuscany.sdo
托斯卡纳sdo impl
1.1.1
org.apache.tuscany.sdo
托斯卡纳sdo图书馆
1.1.1
org.apache.tuscany.sdo
托斯卡纳sdo工具
1.1.1
安装
org.apache.maven.plugins
maven编译器插件
2.0.2
1.6
1.6
UTF-8
org.apache.maven.plugins
maven资源插件
2.4.3
UTF-8
org.apache.felix
maven捆绑插件
2.3.6
真的
${project.artifactId}
*,org.apache.camel.osgi
com.bssys
camel-context.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated by Apache ServiceMix Archetype -->
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:osgi="http://camel.apache.org/schema/osgi"
       xmlns:osgix="http://www.springframework.org/schema/osgi-compendium"
       xmlns:ctx="http://www.springframework.org/schema/context"
       xmlns:jaxws="http://cxf.apache.org/jaxws"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
       http://camel.apache.org/schema/osgi http://camel.apache.org/schema/osgi/camel-osgi.xsd
       http://www.springframework.org/schema/osgi-compendium http://www.springframework.org/schema/osgi-compendium/spring-osgi-compendium.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
       http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
">

  <osgi:camelContext xmlns="http://camel.apache.org/schema/spring">
    <route>
      <from uri="timer://myTimer?fixedRate=true&amp;period=10000"/>
      <bean ref="myTransform" method="transform"/>
      <to uri="log:ExampleRouter"/>
    </route>
  </osgi:camelContext>

  <bean id="myTransform" class="com.bssys.MyTransform">
    <property name="prefix" value="${prefix}"/>
  </bean>

  <osgix:cm-properties id="preProps" persistent-id="com.bssys">
      <prop key="prefix">MyTransform</prop>
  </osgix:cm-properties>

  <ctx:property-placeholder properties-ref="preProps" />

    <!-- HTTP Endpoint -->
    <jaxws:endpoint xmlns:iws="http://www.bssys.com/SMEV/IWS/1"
        id="iws" address="/iws1"
        serviceName="iws:IWSExport_BaseImportIWSHttpService"
        endpointName="iws:IWSExport_BaseImportIWSHttpPort"
        implementor="com.bssys.smev.iws._1.BaseImportIWSImpl">
        <!-- 
        <jaxws:features>
            <bean class="org.apache.cxf.feature.LoggingFeature" />
        </jaxws:features>
         -->
    </jaxws:endpoint>



<!-- 
<camelContext xmlns="http://camel.apache.org/schema/spring">
    <route/>
</camelContext>
 -->

 </beans>

MyTransform

我在tuscany sdo impl/MANIFEST.MF导出包中找到了commonj.sdo.impl,在tuscany sdo api/MANIFEST.MF导入包中找到了commonj.sdo.impl;version=“2.1”对于托斯卡纳sdo api,还可以看到commonj.sdo.impl.HelperProvider类。你能提供spring配置文件吗?我重新检查了JAR并解决了这个问题。HelperProvider确实存在于tuscany-sdo-api-r2.1中,一开始我错了。我将把pom.xml和spring.xml附加到这个问题上。看起来好像没有创建META-INF\services\commonj.sdo.impl.HelperProvider中声明的用于HelperProvider实现的OSGi服务。请在osgi控制台中键入status以确保osgi服务正确启动(它甚至可能需要手动启动)karaf@root>osgi:现状与未来karaf@root>控制台中的状态。它们都不起作用。它说找不到命令:osgi:status。我在tuscany sdo impl/MANIFEST.MF导出包中找到了commonj.sdo.impl,在tuscany sdo api/MANIFEST.MF导入包中找到了commonj.sdo.impl;version=“2.1”对于托斯卡纳sdo api,还可以看到commonj.sdo.impl.HelperProvider类。你能提供spring配置文件吗?我重新检查了JAR并解决了这个问题。HelperProvider确实存在于tuscany-sdo-api-r2.1中,一开始我错了。我将把pom.xml和spring.xml附加到这个问题上。看起来好像没有创建META-INF\services\commonj.sdo.impl.HelperProvider中声明的用于HelperProvider实现的OSGi服务。请在osgi控制台中键入status以确保osgi服务正确启动(它甚至可能需要手动启动)karaf@root>osgi:现状与未来karaf@root>控制台中的状态。它们都不起作用。它说找不到命令:osgi:status。
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <!-- Generated by Apache ServiceMix Archetype -->

    <modelVersion>4.0.0</modelVersion>

    <groupId>com.bssys</groupId>
    <artifactId>eg-smx-osgi-bundle</artifactId>
    <packaging>bundle</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>Apache ServiceMix :: Camel OSGi Bundle</name>

    <properties>
       <camel.version>2.8.3</camel.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-core</artifactId>
            <version>${camel.version}</version>
        </dependency>

        <!-- CXF SDO -->
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-databinding-sdo</artifactId>
            <version>2.4.6</version>
        </dependency>

        <!-- Apache tuscany SDO -->
        <dependency>
            <groupId>org.apache.tuscany.sdo</groupId>
            <artifactId>tuscany-sdo-api-r2.1</artifactId>
            <version>1.1.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tuscany.sdo</groupId>
            <artifactId>tuscany-sdo-impl</artifactId>
            <version>1.1.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tuscany.sdo</groupId>
            <artifactId>tuscany-sdo-lib</artifactId>
            <version>1.1.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tuscany.sdo</groupId>
            <artifactId>tuscany-sdo-tools</artifactId>
            <version>1.1.1</version>
        </dependency>

    </dependencies>

    <build>
        <defaultGoal>install</defaultGoal>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.0.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.4.3</version>
                <configuration>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <version>2.3.6</version>
                <extensions>true</extensions>
                <configuration>
                    <instructions>
                        <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
                        <Import-Package>*,org.apache.camel.osgi</Import-Package>
                        <Private-Package>com.bssys</Private-Package>
                    </instructions>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated by Apache ServiceMix Archetype -->
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:osgi="http://camel.apache.org/schema/osgi"
       xmlns:osgix="http://www.springframework.org/schema/osgi-compendium"
       xmlns:ctx="http://www.springframework.org/schema/context"
       xmlns:jaxws="http://cxf.apache.org/jaxws"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
       http://camel.apache.org/schema/osgi http://camel.apache.org/schema/osgi/camel-osgi.xsd
       http://www.springframework.org/schema/osgi-compendium http://www.springframework.org/schema/osgi-compendium/spring-osgi-compendium.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
       http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
">

  <osgi:camelContext xmlns="http://camel.apache.org/schema/spring">
    <route>
      <from uri="timer://myTimer?fixedRate=true&amp;period=10000"/>
      <bean ref="myTransform" method="transform"/>
      <to uri="log:ExampleRouter"/>
    </route>
  </osgi:camelContext>

  <bean id="myTransform" class="com.bssys.MyTransform">
    <property name="prefix" value="${prefix}"/>
  </bean>

  <osgix:cm-properties id="preProps" persistent-id="com.bssys">
      <prop key="prefix">MyTransform</prop>
  </osgix:cm-properties>

  <ctx:property-placeholder properties-ref="preProps" />

    <!-- HTTP Endpoint -->
    <jaxws:endpoint xmlns:iws="http://www.bssys.com/SMEV/IWS/1"
        id="iws" address="/iws1"
        serviceName="iws:IWSExport_BaseImportIWSHttpService"
        endpointName="iws:IWSExport_BaseImportIWSHttpPort"
        implementor="com.bssys.smev.iws._1.BaseImportIWSImpl">
        <!-- 
        <jaxws:features>
            <bean class="org.apache.cxf.feature.LoggingFeature" />
        </jaxws:features>
         -->
    </jaxws:endpoint>



<!-- 
<camelContext xmlns="http://camel.apache.org/schema/spring">
    <route/>
</camelContext>
 -->

 </beans>