我使用 maven-jaxb2-plugin 成功从多个 wsdl 端点生成 java 类。
这是一次执行:
<execution>
<id>generateDelta</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaLanguage>WSDL</schemaLanguage>
<generatePackage>com.somepackage1</generatePackage>
<schemas>
<schema>
<url>
wsdl_url
</url>
</schema>
</schemas>
</configuration>
</execution>
这里的问题是我有多次执行,从而生成多个类,每次执行将类保存在不同的包中。
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Bapiret2", propOrder = {...})
Babiret2.java 类之一是在多个包中生成的(因此,它来自多个 wdsls)
当我执行使用此 stub 的代码时,例如在单元测试中,我收到以下异常:
org.springframework.oxm.UncategorizedMappingException: Unknown JAXB exception; nested exception is com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions
Two classes have the same XML type name "{urn:sap-com:document:sap:soap:functions:mc-style}Bapiret2". Use @XmlType.name and @XmlType.namespace to assign different names to them.
this problem is related to the following location:
at com.somepackage1.Bapiret2
this problem is related to the following location:
at com.somepackage2.Bapiret2
我发现了一些可能的修复,例如在 args 标签下添加配置
-XautoNameResolution
arg,它不起作用
我测试了更改 XmlType 名称属性是否有效,并且确实有效。还可以向 XmlType 添加命名空间。
问题是我不知道如何在生成类时使用 Maven 添加它
最佳答案
对于每个 wsdl url,在配置元素内,您应该指定 schemaDirectory 和generatePackage 元素,它们应该指向与其他元素不同的名称,因为 schemaDirectory 具有清除指定目录的副作用。
关于java - 如何更新生成的 stub 的 XML-TYPE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45056329/