java Webservice-Client:Spring WS、JAXB 和只有一个 WSDL 文件的通用方法?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6730388/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Webservice-Client: Common approach with Spring WS, JAXB and just one WSDL file?
提问by It's Leto
I would like to use Spring WS to build a Webservice-Client with JAXB for marshalling and unmarshalling the Java classes.
我想使用 Spring WS 构建一个带有 JAXB 的 Webservice-Client 来编组和解组 Java 类。
But what I have is just one WSDL file. When I understand it right, I can generate Java classes with JAXB (xjc.exe), which then can be used by me with Spring WS to retrieve the Webservice-Data and send an answer.
但我只有一个 WSDL 文件。当我理解正确时,我可以使用 JAXB (xjc.exe) 生成 Java 类,然后我可以使用 Spring WS 来检索 Webservice-Data 并发送答案。
But JAXB can only generate Java classes from xsd-schema files. Must I now manually copy those xsd-definitions from within the WSDL file to generate those classes via JAXB? (in my case the WSDL file contains 4 XSD definitions).
但是 JAXB 只能从 xsd-schema 文件生成 Java 类。我现在是否必须从 WSDL 文件中手动复制这些 xsd 定义以通过 JAXB 生成这些类?(在我的例子中,WSDL 文件包含 4 个 XSD 定义)。
Or is there a way to just convert the whole WSDL to Java classes which I can use with Spring WS (I know there is the "wsimport", but it is part of JAX-WS and I think I can't use it in this scenario, right?).
或者有没有办法将整个 WSDL 转换为我可以与 Spring WS 一起使用的 Java 类(我知道有“wsimport”,但它是 JAX-WS 的一部分,我想我不能在这个中使用它场景,对吧?)。
So what is the common approach with Spring WS / JAXB / one WSDL file?
那么Spring WS / JAXB /一个WSDL文件的常用方法是什么?
I really would like to get startet with Spring WS and JAXB - thanks a lot for your help!
我真的很想开始使用 Spring WS 和 JAXB - 非常感谢您的帮助!
采纳答案by skaffman
I can generate Java classes with JAXB (xbj.exe)
我可以使用 JAXB (xbj.exe) 生成 Java 类
xjc
, you mean.
xjc
, 你的意思是。
Must I now manually copy those xsd-definitions from within the WSDL file to generate those classes via JAXB?
我现在是否必须从 WSDL 文件中手动复制这些 xsd 定义以通过 JAXB 生成这些类?
That's one option, certainly. A more automated approach is to write an XSL transform to extract the schema components into temporary files, and then to run XJC over those. A bit more work, but automation is always good.
那当然是一种选择。更自动化的方法是编写 XSL 转换以将模式组件提取到临时文件中,然后在这些文件上运行 XJC。做更多的工作,但自动化总是好的。
I know there is the "wsimport", but it is part of JAX-WS and I think I can't use it in this scenario, right?
我知道有“wsimport”,但它是 JAX-WS 的一部分,我想我不能在这种情况下使用它,对吧?
Actually, JAX-WS artifacts are just a decorated form of JAXB. wsimport
will produce some JAX-WS-specific stuff, plus the standard JAXB artifacts representing the schema components. You should be able to use the JAXB generated classes for Spring-WS, and ignore the JAX-WS-specific ones.
实际上,JAX-WS 工件只是 JAXB 的一种装饰形式。wsimport
将产生一些 JAX-WS 特定的东西,加上代表模式组件的标准 JAXB 工件。您应该能够将 JAXB 生成的类用于 Spring-WS,而忽略特定于 JAX-WS 的类。