简体   繁体   English

由以下原因引起:javax.xml.bind.JAXBException:该上下文不知道此类或其任何超类

[英]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.

相关问题 编组错误:javax.xml.bind.JAXBException:此上下文已知类或其任何超类 - Marshalling error: javax.xml.bind.JAXBException: class nor any of its super class is known to this context javax.xml.bind.JAXBException:class <ClassName> 在这种情况下,也不知道它的任何超类 - javax.xml.bind.JAXBException: class <ClassName> nor any of its super class is known to this context 线程“主”中的异常javax.xml.bind.JAXBException:此上下文已知类或其任何超类 - Exception in thread “main” javax.xml.bind.JAXBException: class nor any of its super class is known to this context javax.xml.bind.JAXBException: Class *** 它的任何超级 class 在此上下文中都是已知的 - javax.xml.bind.JAXBException: Class *** nor any of its super class is known to this context javax.xml.bind.MarshalException-带有链接的异常:[javax.xml.bind.JAXBException:class **或其任何超类对此上下文都是已知的 - javax.xml.bind.MarshalException - with linked exception: [javax.xml.bind.JAXBException: class ** nor any of its super class is known to this context JAXB ANY 元素添加编组错误 javax.xml.bind.JAXBException: class *** 或其任何超类在此上下文中都是已知的 - JAXB ANY element add marhalling error javax.xml.bind.JAXBException: class *** nor any of its super class is known to this context javax.xml.bind.JAXBException: class java.util.ArrayList nor any of its super class is known to this context - javax.xml.bind.JAXBException: class java.util.ArrayList nor any of its super class is known to this context JAXBException: SaveButton 或其任何超类在此上下文中都是已知的 - JAXBException: SaveButton nor any of its super class is known to this context JAXBException UnmarshallerImpl或其任何超类对此上下文都是已知的 - JAXBException UnmarshallerImpl nor any of its super class is known to this context 此上下文已知javax.xml.bind.MarshalException或其任何超类 - javax.xml.bind.MarshalException nor any of its super class is known to this context
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM