Java 使用xjc和自定义绑定文件注入注释
嗯,我有这样的外部(和旧的)WSDL结构:Java 使用xjc和自定义绑定文件注入注释,java,jaxb,wsdl,xjc,xjb,Java,Jaxb,Wsdl,Xjc,Xjb,嗯,我有这样的外部(和旧的)WSDL结构: <wsdl:definitions xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mi
<wsdl:definitions xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:tns="...custom namespace..."
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
targetNamespace="...custom namespace..."
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="...custom namespace...">
<s:element name="...">
</s:element>
<s:element name="...">
</s:element>
<s:complexType name="CustomClassName">
...
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<jaxb:bindings
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:annox="http://annox.dev.java.net"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
jaxb:extensionBindingPrefixes="xjc annox" version="2.1">
<jaxb:bindings schemaLocation="...wsdl filename..." node="//s:schema">
<jaxb:bindings node="s:complexType[@name='CustomClassName']">
<annox:annotate>
<annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement" />
</annox:annotate>
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>
...
我使用xjc从这个WSDL创建Java类
我使用的来自此WSDL的请求以以CustomClassName开头的纯XML响应,但该类没有使用XMLRootElement注释
当我手动将此注释添加到此类时,我的代码工作正常
但是我想在调用xjc时使用自定义绑定文件来添加注释,而a.t.m.我无法实现这一点。我当前的自定义绑定文件如下所示:
<wsdl:definitions xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:tns="...custom namespace..."
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
targetNamespace="...custom namespace..."
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="...custom namespace...">
<s:element name="...">
</s:element>
<s:element name="...">
</s:element>
<s:complexType name="CustomClassName">
...
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<jaxb:bindings
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:annox="http://annox.dev.java.net"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
jaxb:extensionBindingPrefixes="xjc annox" version="2.1">
<jaxb:bindings schemaLocation="...wsdl filename..." node="//s:schema">
<jaxb:bindings node="s:complexType[@name='CustomClassName']">
<annox:annotate>
<annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement" />
</annox:annotate>
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>
(我尝试了我发现的不同语法,但该类仍然没有注释。)
我的错误在哪里?似乎定制没有连接到WSDL。我记得有几个关于同一个问题的问题。因为它不是这个问题的解决方案,所以我将它作为一个注释发布:我在这些答案中找到了另一种方法:(在使用JAXBElement和XMLStreamReader时不需要XMLRootElement注释)似乎定制没有附加到WSDL。我记得有几个关于同一个问题的问题。因为它不是这个问题的解决方案,所以我将它作为一个注释发布:我在这些答案中找到了另一种方法:(在使用JAXBElement和XMLStreamReader时不需要XMLRootElement注释)