java如何使用jaxb从多个WSDL文件生成类
我有两个SOAP API需要通过后端API连接。我有两个不同的WSDL文件:commercial。wsdl和使用者。wsdl。问题在于WBAHS120505F02327和消费者。wsdl共享XML名称。当我尝试运行该程序时,出现以下错误:
Two classes have the same XML type name "{https://secure.xxx.co.za/xxx}EmpiricaEM04". Use @XmlType.name and @XmlType.namespace to assign different names to them.
jaxb有没有一种方法可以为wsdl文件和共享公共类生成类?如果没有,还有别的办法吗?我无法更改wsdl文件,必须按照提供给我的方式使用它们
生成的商业类: EmpericaEM04。java
//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.3.0
// See <a href="https://javaee.github.io/jaxb-v2/">https://javaee.github.io/jaxb-v2/</a>
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2021.05.27 at 08:39:41 AM SAST
//
package com.soap.api.xxx.commercial;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for EmpiricaEM04 complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* <complexType name="EmpiricaEM04">
* <complexContent>
* <extension base="{https://secure.xxx.co.za/TUBureau}Empirica">
* <sequence>
* <element name="ConsumerNo" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* <element name="EmpiricaScore" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* <element name="ExclusionCode" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* <element name="ExclusionCodeDescription" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* <element name="ReasonCode" type="{https://secure.xxx.co.za/TUBureau}ArrayOfString" minOccurs="0"/>
* <element name="ReasonDescription" type="{https://secure.xxx.co.za/TUBureau}ArrayOfString" minOccurs="0"/>
* <element name="ExpansionScore" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* <element name="ExpansionScoreDescription" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* </sequence>
* </extension>
* </complexContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "EmpiricaEM04", propOrder = {
"consumerNo",
"empiricaScore",
"exclusionCode",
"exclusionCodeDescription",
"reasonCode",
"reasonDescription",
"expansionScore",
"expansionScoreDescription"
})
public class EmpiricaEM04
extends Empirica
{
@XmlElement(name = "ConsumerNo")
protected String consumerNo;
@XmlElement(name = "EmpiricaScore")
protected String empiricaScore;
@XmlElement(name = "ExclusionCode")
protected String exclusionCode;
@XmlElement(name = "ExclusionCodeDescription")
protected String exclusionCodeDescription;
@XmlElement(name = "ReasonCode")
protected ArrayOfString reasonCode;
@XmlElement(name = "ReasonDescription")
protected ArrayOfString reasonDescription;
@XmlElement(name = "ExpansionScore")
protected String expansionScore;
@XmlElement(name = "ExpansionScoreDescription")
protected String expansionScoreDescription;
/**
* Gets the value of the consumerNo property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getConsumerNo() {
return consumerNo;
}
/**
* Sets the value of the consumerNo property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setConsumerNo(String value) {
this.consumerNo = value;
}
/**
* Gets the value of the empiricaScore property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getEmpiricaScore() {
return empiricaScore;
}
/**
* Sets the value of the empiricaScore property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setEmpiricaScore(String value) {
this.empiricaScore = value;
}
/**
* Gets the value of the exclusionCode property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getExclusionCode() {
return exclusionCode;
}
/**
* Sets the value of the exclusionCode property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setExclusionCode(String value) {
this.exclusionCode = value;
}
/**
* Gets the value of the exclusionCodeDescription property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getExclusionCodeDescription() {
return exclusionCodeDescription;
}
/**
* Sets the value of the exclusionCodeDescription property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setExclusionCodeDescription(String value) {
this.exclusionCodeDescription = value;
}
/**
* Gets the value of the reasonCode property.
*
* @return
* possible object is
* {@link ArrayOfString }
*
*/
public ArrayOfString getReasonCode() {
return reasonCode;
}
/**
* Sets the value of the reasonCode property.
*
* @param value
* allowed object is
* {@link ArrayOfString }
*
*/
public void setReasonCode(ArrayOfString value) {
this.reasonCode = value;
}
/**
* Gets the value of the reasonDescription property.
*
* @return
* possible object is
* {@link ArrayOfString }
*
*/
public ArrayOfString getReasonDescription() {
return reasonDescription;
}
/**
* Sets the value of the reasonDescription property.
*
* @param value
* allowed object is
* {@link ArrayOfString }
*
*/
public void setReasonDescription(ArrayOfString value) {
this.reasonDescription = value;
}
/**
* Gets the value of the expansionScore property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getExpansionScore() {
return expansionScore;
}
/**
* Sets the value of the expansionScore property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setExpansionScore(String value) {
this.expansionScore = value;
}
/**
* Gets the value of the expansionScoreDescription property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getExpansionScoreDescription() {
return expansionScoreDescription;
}
/**
* Sets the value of the expansionScoreDescription property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setExpansionScoreDescription(String value) {
this.expansionScoreDescription = value;
}
}
生成的消费者类别:EmpericaEM04。java
//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.3.0
// See <a href="https://javaee.github.io/jaxb-v2/">https://javaee.github.io/jaxb-v2/</a>
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2021.05.26 at 04:38:27 PM SAST
//
package com.soap.api.xxx.consumer;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for EmpiricaEM04 complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* <complexType name="EmpiricaEM04">
* <complexContent>
* <extension base="{https://secure.xxx.co.za/TUBureau}Empirica">
* <sequence>
* <element name="ConsumerNo" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* <element name="EmpiricaScore" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* <element name="ExclusionCode" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* <element name="ExclusionCodeDescription" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* <element name="ReasonCode" type="{https://secure.xxx.co.za/TUBureau}ArrayOfString" minOccurs="0"/>
* <element name="ReasonDescription" type="{https://secure.xxx.co.za/TUBureau}ArrayOfString" minOccurs="0"/>
* <element name="ExpansionScore" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* <element name="ExpansionScoreDescription" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* </sequence>
* </extension>
* </complexContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "EmpiricaEM04", propOrder = {
"consumerNo",
"empiricaScore",
"exclusionCode",
"exclusionCodeDescription",
"reasonCode",
"reasonDescription",
"expansionScore",
"expansionScoreDescription"
})
public class EmpiricaEM04
extends Empirica
{
@XmlElement(name = "ConsumerNo")
protected String consumerNo;
@XmlElement(name = "EmpiricaScore")
protected String empiricaScore;
@XmlElement(name = "ExclusionCode")
protected String exclusionCode;
@XmlElement(name = "ExclusionCodeDescription")
protected String exclusionCodeDescription;
@XmlElement(name = "ReasonCode")
protected ArrayOfString reasonCode;
@XmlElement(name = "ReasonDescription")
protected ArrayOfString reasonDescription;
@XmlElement(name = "ExpansionScore")
protected String expansionScore;
@XmlElement(name = "ExpansionScoreDescription")
protected String expansionScoreDescription;
/**
* Gets the value of the consumerNo property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getConsumerNo() {
return consumerNo;
}
/**
* Sets the value of the consumerNo property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setConsumerNo(String value) {
this.consumerNo = value;
}
/**
* Gets the value of the empiricaScore property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getEmpiricaScore() {
return empiricaScore;
}
/**
* Sets the value of the empiricaScore property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setEmpiricaScore(String value) {
this.empiricaScore = value;
}
/**
* Gets the value of the exclusionCode property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getExclusionCode() {
return exclusionCode;
}
/**
* Sets the value of the exclusionCode property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setExclusionCode(String value) {
this.exclusionCode = value;
}
/**
* Gets the value of the exclusionCodeDescription property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getExclusionCodeDescription() {
return exclusionCodeDescription;
}
/**
* Sets the value of the exclusionCodeDescription property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setExclusionCodeDescription(String value) {
this.exclusionCodeDescription = value;
}
/**
* Gets the value of the reasonCode property.
*
* @return
* possible object is
* {@link ArrayOfString }
*
*/
public ArrayOfString getReasonCode() {
return reasonCode;
}
/**
* Sets the value of the reasonCode property.
*
* @param value
* allowed object is
* {@link ArrayOfString }
*
*/
public void setReasonCode(ArrayOfString value) {
this.reasonCode = value;
}
/**
* Gets the value of the reasonDescription property.
*
* @return
* possible object is
* {@link ArrayOfString }
*
*/
public ArrayOfString getReasonDescription() {
return reasonDescription;
}
/**
* Sets the value of the reasonDescription property.
*
* @param value
* allowed object is
* {@link ArrayOfString }
*
*/
public void setReasonDescription(ArrayOfString value) {
this.reasonDescription = value;
}
/**
* Gets the value of the expansionScore property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getExpansionScore() {
return expansionScore;
}
/**
* Sets the value of the expansionScore property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setExpansionScore(String value) {
this.expansionScore = value;
}
/**
* Gets the value of the expansionScoreDescription property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getExpansionScoreDescription() {
return expansionScoreDescription;
}
/**
* Sets the value of the expansionScoreDescription property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setExpansionScoreDescription(String value) {
this.expansionScoreDescription = value;
}
}
SoapConfig。Java
@Configuration
public class SoapConfig {
@Bean
public Jaxb2Marshaller marshaller() {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
String[] packages = {"com.soap.api.xxx.commercial", "com.soap.api.xxx.consumer"};
marshaller.setPackagesToScan(packages);
return marshaller;
}
}
我必须分别生成这些类,因为如果我尝试同时生成这两个类,就会出现一个错误,说明类名已经创建
POM。xml
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.14.0</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<args>
<arg>-XautoNameResolution</arg>
</args>
<generatePackage>com.soap.api.xxx.commercial</generatePackage>
<generateDirectory>${project.basedir}/src/main/java</generateDirectory>
<schemaDirectory>${project.basedir}/src/main/resources/wsdl</schemaDirectory>
<schemaIncludes>
<include>*.wsdl</include>
</schemaIncludes>
</configuration>
</plugin>
完全错误
Two classes have the same XML type name "{https://secure.xxx.co.za/TUBureau}EmpiricaEM04". Use @XmlType.name and @XmlType.namespace to assign different names to them.
this problem is related to the following location:
at com.soap.api.xxx.commercial.EmpiricaEM04
at @javax.xml.bind.annotation.XmlSeeAlso(value={com.soap.api.xxx.commercial.EmpiricaEM04.class, com.soap.api.xxx.commercial.EmpiricaE1.class})
at @javax.xml.bind.annotation.XmlSeeAlso(value={com.soap.api.xxx.commercial.AccountVerificationVA.class, com.soap.api.xxx.commercial.ComplianceIndicatorLI.class
共 (0) 个答案