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

这些其他问题暗示了一个解决方案,但我无法让它工作:
Could not resolve a binding for http://schemas.xmlsoap.org/wsdl/soap/
ServiceConstructionException when creating a CXF web service client
How to package an Apache CXF application into a monolithic JAR with the Maven “shade” plugin

当我通过执行java -Xdebug -jar myapp.jar启动我的应用程序时,我得到一个ServiceConstructionException:当应用程序进行SOAP调用时,无法解析null的绑定.当我在IntelliJ中启动应用程序时,应用程序和SOAP调用工作正常.以下是重现错误的最小示例:https://github.com/stianlagstad/mainclass-and-jxf-problems-demo

重现步骤:
– gradle clean build&& java -Xdebug -jar build / libs / mainclass-and-jxf-problems-demo.jar
– 转到http://localhost:4242/endpoint/并查看错误

任何人都可以帮我弄清楚我必须做哪些改变才能使SOAP调用工作?

编辑以提供更多信息:

如果我编辑build.gradle以不排除meta-inf(即具有configurations.compile.collect {it.isDirectory()?it:zipTree(it)}而不是configurations.compile.collect {it.isDirectory()?it: zipTree(it).matching {exclude {it.path.contains(‘meta-inf’)}}})我得到了这个错误错误:无法找到或加载主类com.shadowjarcxfproblem.JettyLauncher(启动应用程序时)作为一个罐子).然而,在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

解决方法:

看完这两个并尝试了一堆不同的东西后,我终于偶然发现了一些有效的东西!
How to package an Apache CXF application into a monolithic JAR with the Maven “shade” plugin
https://discuss.gradle.org/t/how-do-i-use-the-gradle-shadow-plugin-to-merge-spring-handlers-and-spring-schemas-files-of-multiple-spring-jar-dependencies/6713/6

使用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'
    }
}

相关文章

安装环境都很简单,就是下载工具需要在华为开发者联盟里注册...
上传的方式有两种,第一种是通过bintray官方出的插件bintray...
转载自: 完美解决Error:SSLpeershutdownincorrectly打开gr...
https://www.jianshu.com/p/9220227cdfb3buildscript{ext.ko...
Markdown版本笔记我的GitHub首页我的博客我的微信我的邮箱My...
 跟着教程做的,已经有了JDK,直接进行后面的步骤,下载安装...