Web Services 错误:java.lang.类转换异常:类组织,apache.cxf,总线,Spring,Spring总线工厂

kuhbmx9i  于 2022-11-15  发布在  Java
关注(0)|答案(3)|浏览(171)

西洛!
我正在尝试使用CXF创建一个Web服务客户端。我的应用程序在OSGi中。我使用Felix框架。
但会发生以下错误:
``
`

[main] ERROR org.apache.cxf.BusFactory - Failed to determine BusFactory implementation class name.
java.lang.ClassCastException: class org.apache.cxf.bus.spring.SpringBusFactory
    at java.lang.Class.asSubclass(Unknown Source)
    at org.apache.cxf.BusFactory.getBusFactoryClass(BusFactory.java:280)
    at org.apache.cxf.BusFactory.newInstance(BusFactory.java:207)
    at org.apache.cxf.BusFactory.newInstance(BusFactory.java:194)
    at org.apache.cxf.BusFactory.getDefaultBus(BusFactory.java:90)
    at org.apache.cxf.BusFactory.getThreadDefaultBus(BusFactory.java:137)
    at org.apache.cxf.BusFactory.getThreadDefaultBus(BusFactory.java:122)
    at org.apache.cxf.jaxws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:89)
    at javax.xml.ws.Service.<init>(Service.java:36)
    at myorg.engine.test.mocks.soapservice.client.CHMService.<init>(CHMService.java:42)
    at myorg.engine.service.OSGiServiceTest.testSoapServiceMock(OSGiServiceTest.java:133)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.ops4j.pax.exam.raw.extender.intern.ProbeInvokerImpl.injectContextAndInvoke(ProbeInvokerImpl.java:112)
    at org.ops4j.pax.exam.raw.extender.intern.ProbeInvokerImpl.findAndInvoke(ProbeInvokerImpl.java:71)
    at org.ops4j.pax.exam.raw.extender.intern.ProbeInvokerImpl.call(ProbeInvokerImpl.java:58)
    at org.ops4j.pax.exam.nat.internal.NativeTestContainer.call(NativeTestContainer.java:83)
    at org.ops4j.pax.exam.spi.reactors.EagerSingleStagedReactor.invoke(EagerSingleStagedReactor.java:85)
    at org.ops4j.pax.exam.junit.JUnit4TestRunner$2.evaluate(JUnit4TestRunner.java:259)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at org.ops4j.pax.exam.junit.JUnit4TestRunner.run(JUnit4TestRunner.java:86)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

[main] ERROR org.apache.cxf.BusFactory - Failed to instantiate bus factory.
java.lang.ClassCastException: class org.apache.cxf.bus.spring.SpringBusFactory
    at java.lang.Class.asSubclass(Unknown Source)
    at org.apache.cxf.BusFactory.newInstance(BusFactory.java:218)
    at org.apache.cxf.BusFactory.newInstance(BusFactory.java:194)
    at org.apache.cxf.BusFactory.getDefaultBus(BusFactory.java:90)
    at org.apache.cxf.BusFactory.getThreadDefaultBus(BusFactory.java:137)
    at org.apache.cxf.BusFactory.getThreadDefaultBus(BusFactory.java:122)
    at org.apache.cxf.jaxws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:89)
    at javax.xml.ws.Service.<init>(Service.java:36)
    at myorg.engine.test.mocks.soapservice.client.CHMService.<init>(CHMService.java:42)
    at myorg.engine.service.OSGiServiceTest.testSoapServiceMock(OSGiServiceTest.java:133)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.ops4j.pax.exam.raw.extender.intern.ProbeInvokerImpl.injectContextAndInvoke(ProbeInvokerImpl.java:112)
    at org.ops4j.pax.exam.raw.extender.intern.ProbeInvokerImpl.findAndInvoke(ProbeInvokerImpl.java:71)
    at org.ops4j.pax.exam.raw.extender.intern.ProbeInvokerImpl.call(ProbeInvokerImpl.java:58)
    at org.ops4j.pax.exam.nat.internal.NativeTestContainer.call(NativeTestContainer.java:83)
    at org.ops4j.pax.exam.spi.reactors.EagerSingleStagedReactor.invoke(EagerSingleStagedReactor.java:85)
    at org.ops4j.pax.exam.junit.JUnit4TestRunner$2.evaluate(JUnit4TestRunner.java:259)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at org.ops4j.pax.exam.junit.JUnit4TestRunner.run(JUnit4TestRunner.java:86)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
[org.ops4j.pax.exam.junit.JUnit4TestRunner] : Exception
org.ops4j.pax.exam.TestContainerException: java.lang.reflect.InvocationTargetException
    at org.ops4j.pax.exam.raw.extender.intern.ProbeInvokerImpl.injectContextAndInvoke(ProbeInvokerImpl.java:118)
    at org.ops4j.pax.exam.raw.extender.intern.ProbeInvokerImpl.findAndInvoke(ProbeInvokerImpl.java:71)
    at org.ops4j.pax.exam.raw.extender.intern.ProbeInvokerImpl.call(ProbeInvokerImpl.java:58)
    at org.ops4j.pax.exam.nat.internal.NativeTestContainer.call(NativeTestContainer.java:83)
    at org.ops4j.pax.exam.spi.reactors.EagerSingleStagedReactor.invoke(EagerSingleStagedReactor.java:85)
    at org.ops4j.pax.exam.junit.JUnit4TestRunner$2.evaluate(JUnit4TestRunner.java:259)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at org.ops4j.pax.exam.junit.JUnit4TestRunner.run(JUnit4TestRunner.java:86)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.ops4j.pax.exam.raw.extender.intern.ProbeInvokerImpl.injectContextAndInvoke(ProbeInvokerImpl.java:112)
    ... 20 more

Caused by: java.lang.RuntimeException: java.lang.ClassCastException: class org.apache.cxf.bus.spring.SpringBusFactory
    at org.apache.cxf.BusFactory.newInstance(BusFactory.java:224)
    at org.apache.cxf.BusFactory.newInstance(BusFactory.java:194)
    at org.apache.cxf.BusFactory.getDefaultBus(BusFactory.java:90)
    at org.apache.cxf.BusFactory.getThreadDefaultBus(BusFactory.java:137)
    at org.apache.cxf.BusFactory.getThreadDefaultBus(BusFactory.java:122)
    at org.apache.cxf.jaxws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:89)
    at javax.xml.ws.Service.<init>(Service.java:36)
    at myorg.engine.test.mocks.soapservice.client.CHMService.<init>(CHMService.java:42)
    at myorg.engine.service.OSGiServiceTest.testSoapServiceMock(OSGiServiceTest.java:133)
    ... 25 more

Caused by: java.lang.ClassCastException: class org.apache.cxf.bus.spring.SpringBusFactory
    at java.lang.Class.asSubclass(Unknown Source)
    at org.apache.cxf.BusFactory.newInstance(BusFactory.java:218)
    ... 33 more

`
``
我说这可能是因为不同的类加载器。有可能吗?
你知道如何解决这个问题吗?
谢谢你!

ssgvzors

ssgvzors1#

是的,看起来你有两个BusFactory类定义。SpringBusFactory实现其中一个,asSubclass()调用在另一个上进行。由于一个BusFactory与另一个不是同一个类,你会得到一个CCE。寻找两个包含BusFactory类的不同包。其中一个将由定义SpringBusFactory的包导入。

5ktev3wc

5ktev3wc2#

我认为“两个BusFactory类定义”是转移注意力的。
不确定您使用的是哪个版本的CXF(猜测是2.4.2),但在查找子类实现时,该代码试图使用线程上下文类加载器来执行ServiceLoader之类的操作。
我最好的猜测是CXF依赖于某种Spring“魔法”,而你缺少提供它的包。看看Karaf的CXF特性,它有大量的依赖项,检查一下并确保你已经得到了所有的依赖项--在这一点上,使用安装了CXF特性的Karaf来尝试这一点可能更容易。
如果您使用的是maven,则可以使用以下命令访问features文件:

<dependency>
        <groupId>org.apache.cxf.karaf</groupId>
        <artifactId>apache-cxf</artifactId>
        <version>2.4.2</version>
        <type>xml</type>
        <classifier>features</classifier>
    </dependency>

有关总线配置here的一些文档

z0qdvdin

z0qdvdin3#

我在过去的pax-exam中看到过类似的奇怪错误。在“正常”的OSGi环境中,这是否在pax-exam之外运行?Talend Service Factory(http://talend.com/products/tsf)有几个在OSGi中运行的CXF客户端和服务的示例(在单独的示例下载包中),它们都可以工作。

相关问题