[英]Caused by: javax.xml.bind.JAXBException: class nor any of its super class is known to this context
I have the following autogenerated classes from xsd. 我有以下从xsd自动生成的类。
<xs:element name="Add" type="tns:AddType"/>
<xs:complexType name="AddCatalogDataItem">
<xs:complexContent>
<xs:restriction base="tns:AddType">
<xs:sequence>
<xs:element ref="tns:Code"/>
<xs:element ref="tns:Value" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="LoadDataRequest">
<xs:complexContent>
<xs:restriction base="AppDataType">
<xs:sequence>
<xs:element ref="tns:Code"/>
<xs:element ref="tns:RegCode" minOccurs="0"/>
<xs:element ref="tns:Add" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
While creating an request during marshalling stage i'm getting this error: 在编组阶段创建请求时,出现此错误:
Caused by: javax.xml.bind.JAXBException: class com.ats.vis.services.concentrator.AddCatalogDataItem nor any of its super class is known to this context. 原因:javax.xml.bind.JAXBException:类com.ats.vis.services.concentrator.AddCatalogDataItem或其任何超类对此上下文都是已知的。
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "LoadDataRequest")
public class LoadDataRequest
extends AppDataType {}
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "AddType", propOrder = {
"any"
})
@XmlSeeAlso({
AddCatalogDataItem.class,
AddCatalogDataResult.class
})
public class AddType {}
Here is the piece of code of creation. 这是创建的代码。
LoadDataRequest appdt = new LoadDataRequest();
AddCatalogDataItem add = new AddCatalogDataItem();
add.getAny().add(new JAXBElement<String>(new QName(NS_CONC, "Code"),String.class, updateOper.code));
аppdt.getAny().add(add);
And code of marshaller. 以及编组器代码。
private SOAPMessage createSOAPRequest(LoadDataRequest request) throws SOAPException, JAXBException {
SOAPMessage message = MessageFactory.newInstance().createMessage();
Marshaller marshaller = JAXBContext.newInstance(request.getClass()).createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
JAXBElement<LoadDataRequest> jaxbElement = new JAXBElement<>(new QName(NS_CONC, "LoadDataRequest"), LoadDataRequest.class, request);
marshaller.marshal(jaxbElement, message.getSOAPBody());
return message;
}
I'm running out of ideas what is wrong with this code. 我的想法用完了,这段代码出了什么问题。 Please, help.
请帮忙。
I've solved the issue by creating jaxb context using following method: 我通过使用以下方法创建jaxb上下文解决了该问题:
JAXBContext jaxb = JAXBContext.newInstance("com.ats.vis.services.concentrator", com.ats.vis.services.concentrator.LoadDataRequest.class.getClassLoader());
Marshaller marshaller = jaxb.createMarshaller();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.