Java 如何防止在 CXF Web 服务客户端中生成 JAXBElement<String>?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4413281/
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
How do I prevent JAXBElement<String> from being generated in a CXF Web Service client?
提问by ScArcher2
I'm trying to create a web service client using CXF to consume a WCF web service. When I use wsdl2java it generates objects with JAXBElement types instead of String.
我正在尝试使用 CXF 创建一个 Web 服务客户端来使用 WCF Web 服务。当我使用 wsdl2java 时,它生成具有 JAXBElement 类型而不是 String 的对象。
I read about using a jaxb bindings.xml file to set generateElementProperty="false" to try to fix the problem, but the web service I'm consuming contains 7 imported schemas.
我阅读了有关使用 jaxb bindings.xml 文件设置 generateElementProperty="false" 以尝试解决问题的信息,但我使用的 Web 服务包含 7 个导入的模式。
How can I specify the generateElementProperty="false"
on all seven schemas, or is there a way to apply it to all schemas?
如何generateElementProperty="false"
在所有七个模式上指定,或者有没有办法将其应用于所有模式?
采纳答案by priya
You have to create a binding file as below, this will get applied globally and use it as wsdl2java - b "bindings.txt" "wsdl"
您必须创建一个如下的绑定文件,这将被全局应用并将其用作 wsdl2java - b "bindings.txt" "wsdl"
<jaxb:bindings version="2.1"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<jaxb:globalBindings generateElementProperty="false"/>
</jaxb:bindings>
回答by yglodt
Note that in my case I had to use <xjc:simple
in my jaxb binding file to get rid of the JAXBElement
request and response wrappers in the @Endpoint
:
请注意,在我的情况下,我必须<xjc:simple
在我的 jaxb 绑定文件中使用以摆脱以下内容中的JAXBElement
请求和响应包装器@Endpoint
:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" elementFormDefault="qualified" attributeFormDefault="unqualified" jaxb:extensionBindingPrefixes="xjc" jaxb:version="2.1">
<xs:annotation>
<xs:appinfo>
<jaxb:globalBindings>
<xjc:simple /><!-- it did only work after adding this -->
</jaxb:globalBindings>
</xs:appinfo>
</xs:annotation>
</xs:schema>