JAXB 生成 JAXBElement<String>而不是字符串
我正在使用 Apache CXF
cxf-codegen-plugin
Maven
插件从 WSDL
文件生成源代码.问题是我生成了 JAXBElement<String>
而不是 String
.我添加了 jaxb-bindings.xml
文件,如下所示:
I am using Apache CXF
cxf-codegen-plugin
Maven
plugin to generate sources from WSDL
file. Problem is that I get JAXBElement<String>
generated instead of String
. I have added the jaxb-bindings.xml
file which looks like this:
<jaxb:bindings version="2.1"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb">
<jaxb:globalBindings generateElementProperty="false"/>
</jaxb:bindings>
这应该防止 JAXB
生成 JAXBElement
.但它不起作用我仍然生成 JAXBElement<String>
而不是 String
.
This should prevent JAXB
to generate JAXBElement<String>
. But it is not working I still have JAXBElement<String>
generated instead of String
.
我的 Maven
插件如下所示:
My Maven
plugin looks like this:
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>${cxf.runtime.version}</version>
<dependencies>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-bindings-soap</artifactId>
<version>${cxf.runtime.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>generate-jaxb</id>
<phase>generate-sources</phase>
<configuration>
<additionalJvmArgs>-Dfile.encoding=UTF8</additionalJvmArgs>
<wsdlOptions>
<wsdlOption>
<wsdl>src/main/resources/wsdl/Cubiks.wsdl</wsdl>
<extraargs>
<extraarg>-b</extraarg>
<extraarg>${basedir}/jaxb-bindings.xml</extraarg>
<extraarg>-b</extraarg>
<extraarg>${basedir}/jaxws-bindings.xml</extraarg>
<extraarg>-exsh</extraarg>
<extraarg>true</extraarg>
<extraarg>-wsdlLocation</extraarg>
<extraarg></extraarg>
</extraargs>
</wsdlOption>
<wsdlOption>
<wsdl>src/main/resources/wsdl/CubiksCallBackService.wsdl</wsdl>
<extraargs>
<extraarg>-b</extraarg>
<extraarg>${basedir}/jaxws-bindings.xml</extraarg>
<extraarg>-b</extraarg>
<extraarg>${basedir}/jaxb-bindings.xml</extraarg>
<extraarg>-exsh</extraarg>
<extraarg>true</extraarg>
<extraarg>-p</extraarg>
<extraarg>com.cubiks.ws.callback</extraarg>
<extraarg>-wsdlLocation</extraarg>
<extraarg></extraarg>
</extraargs>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
CXF
版本为 2.6.0
.有人知道问题出在哪里吗?
CXF
version is 2.6.0
. Does someone know where might be the problem?
编辑
XSD 非常庞大.这是生成 JAXBElement
The XSD is very huge. This is the element which generating JAXBElement<String>
<xs:complexType name="ServiceResponse">
<xs:sequence>
<xs:element minOccurs="0" name="RequestStatus" type="tns:RequestStatus"/>
<xs:element minOccurs="0" name="RequestStatusDescription" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:element name="ServiceResponse" nillable="true" type="tns:ServiceResponse"/>
而生成的来源是:
@XmlElementRef(name = "RequestStatusDescription", namespace = "http://www.cubiksonline.com/2009/08/AssessmentProvider", type = JAXBElement.class)
protected JAXBElement<String> requestStatusDescription;
推荐答案
我要做的就是用另一个 jaxb:bindings
包装 jaxb:globalBindings
.
What I had to do is to wrap jaxb:globalBindings
with another jaxb:bindings
.
<jaxb:bindings version="2.0"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb">
<jaxb:bindings>
<jaxb:globalBindings generateElementProperty="false"/>
</jaxb:bindings>
</jaxb:bindings>
现在一切正常,不再生成 JAXBElement
.
Now everything is working, there is no JAXBElement<String>
generated anymore.
相关文章