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

2024-04-29

这些其他问题暗示了解决方案,但我无法让它发挥作用:
无法解析 http://schemas.xmlsoap.org/wsdl/soap/ 的绑定 https://stackoverflow.com/questions/26159206/could-not-resolve-a-binding-for-http-schemas-xmlsoap-org-wsdl-soap
创建 CXF Web 服务客户端时出现 ServiceConstructionException https://stackoverflow.com/questions/3006185/serviceconstructionexception-when-creating-a-cxf-web-service-client
如何使用 Maven“shade”插件将 Apache CXF 应用程序打包到整体 JAR 中 https://stackoverflow.com/questions/6831954/how-to-package-an-apache-cxf-application-into-a-monolithic-jar-with-the-maven-s

当我开始我的申请时java -Xdebug -jar myapp.jar我得到了一个ServiceConstructionException: Could not resolve a binding for null当应用程序进行 SOAP 调用时。当我在 IntelliJ 中启动应用程序时,应用程序和 SOAP 调用工作得很好。这是重现错误的最小示例:https://github.com/stianlagstad/mainclass-and-jxf-problems-demo 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/端点/ 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')}} })我得到这个错误:Error: Could not find or load main class com.shadowjarcxfproblem.JettyLauncher(当将应用程序作为 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

在阅读了这两本并尝试了很多不同的事情之后,我终于偶然发现了一些有用的东西!

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-依赖项/6713/6 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'
    }
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

创建 CXF Web 服务客户端时出现 ServiceConstructionException (scala+java+wsdl2java) 的相关文章

随机推荐