maven之使用 JAX-WS + xjc + 绑定(bind)将可序列化和默认 UID 添加到我的 WSDL stub
落叶无声
阅读:45
2025-02-15 21:57:57
评论:0
我正在尝试使用 globalBindings 元素向我的 WSDL stub 类添加可序列化和默认 UID,这样我就可以摆脱来自 Eclipse 的一堆烦人的警告。
我正在尝试遵循 this answer 中的建议,但没有运气。仍然在 Eclipse 中得到所有警告。
我是不是在 pom 文件中遗漏了什么?
如果需要,我可以升级到更新版本的 jaxws 插件,甚至可以移动到不同的插件。
这是我的绑定(bind)文件:
<bindings xmlns="http://java.sun.com/xml/ns/jaxb" xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.1"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc">
<globalBindings>
<xjc:serializable uid="1" />
</globalBindings>
<bindings
schemaLocation="../resources/com/satorisoftware/ws/infuseiac/intladdresscorrection/intladdresscorrection.wsdl#types?schema3"
version="1.0">
<schemaBindings>
<package name="com.satorisoftware.ws.infuseiac-intladdresscorrection" />
</schemaBindings>
<!-- Tell JAXB to generate Java class specifically named CorrectRequestElement
for this element, to avoid the name clash that automatic naming causes. -->
<bindings node="//xsd:element[@name='CorrectRequest']">
<class name="CorrectRequestElement" />
</bindings>
</bindings>
</bindings>
这是我的 pom.xml 文件的相关部分:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>1.12</version>
<executions>
<execution>
<id>import-iac-wsdl</id>
<phase>generate-sources</phase>
<goals>
<goal>wsimport</goal>
</goals>
<inherited>false</inherited>
<configuration>
<packageName>com.satorisoftware.ws.infuseiac.intladdresscorrection</packageName>
<wsdlLocation>com/satorisoftware/ws/infuseiac/intladdresscorrection/intladdresscorrection.wsdl</wsdlLocation>
<staleFile>${project.build.directory}/jaxws/stale/wsdl.intladdresscorrection.done</staleFile>
<sourceDestDir>${project.build.directory}/generated/jaxws-infuseiac-intladdresscorrection</sourceDestDir>
<wsdlDirectory>src/main/resources/com/satorisoftware/ws/infuseiac/intladdresscorrection</wsdlDirectory>
<bindingFiles>
<!-- See http://www.jroller.com/gmazza/entry/enhancing_jaxb_artifacts#BindingFile
for an end-to-end-example of doing bindings files for WSDL files. -->
<bindingFile>${basedir}/src/main/bindings/bindings-intladdresscorrection.xjb</bindingFile>
</bindingFiles>
<!-- <wsdlUrls> <value>https://infuseiac.satorisoftware.com/wsdl/IntlAddressCorrection.2012.12.wsdl</value>
</wsdlUrls> -->
<!-- Generate JAX-WS 2.0 compatible stubs -->
<target>2.0</target>
</configuration>
</execution>
</executions>
</plugin>
这是一个没有 UID 的生成类的例子
package com.satorisoftware.ws.infuseiac.intladdresscorrection;
import javax.xml.ws.WebFault;
/**
* This class was generated by the JAX-WS RI.
* JAX-WS RI 2.1.7-b01-
* Generated source version: 2.0
*
*/
@WebFault(name = "DuplicateFieldFaultContract", targetNamespace = "infuse.satorisoftware.com/2012/08")
public class IntlAddressCorrectionCorrectDuplicateFieldFaultContractOfInfuseSingleFieldFaultFaultMessage
extends Exception
{
/**
* Java type that goes as soapenv:Fault detail element.
*
*/
private DuplicateFieldFaultContract faultInfo;
/**
*
* @param message
* @param faultInfo
*/
public IntlAddressCorrectionCorrectDuplicateFieldFaultContractOfInfuseSingleFieldFaultFaultMessage(String message, DuplicateFieldFaultContract faultInfo) {
super(message);
this.faultInfo = faultInfo;
}
/**
*
* @param message
* @param faultInfo
* @param cause
*/
public IntlAddressCorrectionCorrectDuplicateFieldFaultContractOfInfuseSingleFieldFaultFaultMessage(String message, DuplicateFieldFaultContract faultInfo, Throwable cause) {
super(message, cause);
this.faultInfo = faultInfo;
}
/**
*
* @return
* returns fault bean: com.satorisoftware.ws.infuseiac.intladdresscorrection.DuplicateFieldFaultContract
*/
public DuplicateFieldFaultContract getFaultInfo() {
return faultInfo;
}
}
这里有一些请求的 WSDL:
<xsd:complexType name="DuplicateFieldFaultContract">
<xsd:annotation>
<xsd:appinfo>
<GenericType xmlns="http://schemas.microsoft.com/2003/10/Serialization/"
Name="DuplicateFieldFaultContract" Namespace="infuse.satorisoftware.com/2012/08">
<GenericParameter Name="InfuseField"
Namespace="http://schemas.datacontract.org/2004/07/Satori.Infuse.Single" />
</GenericType>
</xsd:appinfo>
</xsd:annotation>
<xsd:complexContent mixed="false">
<xsd:extension base="tns:InfuseFaultContract">
<xsd:sequence>
<xsd:element
xmlns:q4="http://schemas.datacontract.org/2004/07/Satori.Infuse.Single"
name="DuplicateFields" nillable="true" type="q4:ArrayOfInfuseField" />
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:element name="DuplicateFieldFaultContract" nillable="true"
type="tns:DuplicateFieldFaultContract" />
请您参考如下方法:
安德斯
这是我从 WSimport 的帖子中了解到的
- 默认情况下,JAXB 生成的代码不可序列化
- 我们需要添加一种机制来生成用于 POjo 的 UID
- 它不会为异常类创建 serialVersionUID
wsdl2java,默认生成的异常类会有一个serialVersionUID
请尝试 wsdl2java,希望这能解决您的问题
声明
1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。