创建CXF web服务客户端时的ServiceConstructionException(scala+;java+;wsdl2java)

创建CXF web服务客户端时的ServiceConstructionException(scala+;java+;wsdl2java),java,web-services,gradle,soap,cxf,Java,Web Services,Gradle,Soap,Cxf,这些其他问题暗示了一个解决方案,但我一直无法让它起作用: 当我通过执行java-Xdebug-jar myapp.jar启动我的应用程序时,我得到了一个ServiceConstructionException:当应用程序进行SOAP调用时,无法解析null的绑定。当我在IntelliJ中启动应用程序时,应用程序和SOAP调用工作正常。下面是再现错误的最小示例: 复制步骤: -gradle clean build&&java-Xdebug-jar build/libs/mainclass和j

这些其他问题暗示了一个解决方案,但我一直无法让它起作用:


当我通过执行
java-Xdebug-jar myapp.jar
启动我的应用程序时,我得到了一个
ServiceConstructionException:当应用程序进行SOAP调用时,无法解析null的绑定。当我在IntelliJ中启动应用程序时,应用程序和SOAP调用工作正常。下面是再现错误的最小示例:

复制步骤:
-
gradle clean build&&java-Xdebug-jar build/libs/mainclass和jxf problems demo.jar

-转到并查看错误

有人能帮我弄清楚我必须做哪些更改才能使SOAP调用正常工作吗

编辑以提供更多信息:

如果我编辑
build.gradle
以不排除META-INF(即拥有
configurations.compile.collect{it.isDirectory()?it:zipTree(it)}
而不是
configurations.compile.collect{it.isDirectory()?it:zipTree(it)。匹配{exclude{it.path.contains('META-INF')}}
)我得到了这个错误:
错误:无法找到或加载主类com.shadowjarcxfproblem.jettylancher
(当作为jar启动应用程序时)。然而,在IntelliJ中启动应用程序仍然可以工作,SOAP调用也可以工作

cxf错误的堆栈跟踪:

org.apache.cxf.service.factory.ServiceConstructionException: Could not resolve a binding for null
    at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createBindingInfo(AbstractWSDLBasedEndpointFactory.java:352)
    at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpointInfo(AbstractWSDLBasedEndpointFactory.java:259)
    at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint(AbstractWSDLBasedEndpointFactory.java:144)
    at org.apache.cxf.frontend.ClientFactoryBean.create(ClientFactoryBean.java:91)
    at org.apache.cxf.frontend.ClientProxyFactoryBean.create(ClientProxyFactoryBean.java:157)
    at org.apache.cxf.jaxws.JaxWsProxyFactoryBean.create(JaxWsProxyFactoryBean.java:142)
    at com.shadowjarcxfproblem.SoapServiceFactory.create(SoapServiceFactory.java:36)
    at com.shadowjarcxfproblem.service.CalculatorServiceComponent$CalculatorServiceImpl.<init>(CalculatorService.scala:17)
...
Caused by: org.apache.cxf.BusException: No binding factory for namespace http://schemas.xmlsoap.org/soap/ registered.
    at org.apache.cxf.bus.managers.BindingFactoryManagerImpl.getBindingFactory(BindingFactoryManagerImpl.java:93)
    at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createBindingInfo(AbstractWSDLBasedEndpointFactory.java:339)
    ... 75 more
org.apache.cxf.service.factory.ServiceConstructionException:无法解析null的绑定
位于org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createBindingInfo(AbstractWSDLBasedEndpointFactory.java:352)
位于org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpointInfo(AbstractWSDLBasedEndpointFactory.java:259)
位于org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint(AbstractWSDLBasedEndpointFactory.java:144)
位于org.apache.cxf.frontend.ClientFactoryBean.create(ClientFactoryBean.java:91)
位于org.apache.cxf.frontend.ClientProxyFactoryBean.create(ClientProxyFactoryBean.java:157)
位于org.apache.cxf.jaxws.JaxWsProxyFactoryBean.create(JaxWsProxyFactoryBean.java:142)
位于com.shadowjarcxfproblem.SoapServiceFactory.create(SoapServiceFactory.java:36)
在com.shadowjarcxfproblem.service.CalculatorServiceComponent$calculatorservicecimpl.(CalculatorService.scala:17)
...
原因:org.apache.cxf.BusException:命名空间没有绑定工厂http://schemas.xmlsoap.org/soap/ 注册的。
位于org.apache.cxf.bus.managers.BindingFactoryManagerImpl.getBindingFactory(BindingFactoryManagerImpl.java:93)
位于org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createBindingInfo(AbstractWSDLBasedEndpointFactory.java:339)
... 75多

在阅读了这两篇文章并尝试了一系列不同的方法之后,我终于发现了一些有效的方法

将gradle shadowjar插件用于此任务解决了以下问题:

import com.github.jengelman.gradle.plugins.shadow.transformers.ServiceFileTransformer
shadowJar {
    // Make sure the cxf service files are handled correctly so that the SOAP services work.
    // Ref https://stackoverflow.com/questions/45005287/serviceconstructionexception-when-creating-a-cxf-web-service-client-scalajava
    transform(ServiceFileTransformer) {
        path = 'META-INF/cxf'
        include 'bus-extensions.txt'
    }
}

您好,我也遇到同样的问题,我尝试将上述代码片段添加到我的构建文件中,但不起作用,您能帮我吗?如果您创建一个可复制的示例并将其放到GitHub上,我可能会帮上忙:)我有一个liferay dxp工作区,请告诉我您是否熟悉liferay,我可以共享存储库。