编组错误 - 缺少 xmlrootelement 注释错误

error in marshalling - missing xmlrootelement annotation error

当我从 spring 项目调用其中一个 WSDL 操作时,出现以下异常 - com.sun.istack.internal.SAXException2: unable to marshal type "com.pkg.wsdl.ABC" as an element because it is missing an @XmlRootElement annotation

我在 pom.xml 中使用以下内容从 WSDL(已被许多客户使用)生成 java 对象作为 spring 项目的一部分 -

        <groupId>org.jvnet.jaxb2.maven2</groupId>
        <artifactId>maven-jaxb2-plugin</artifactId>
        <version>0.13.1</version>

查看类似的问题解决方案,我更改了代码以使用 JAXBElement,但仍然出现相同的错误 -

    ABC vabc = new ABC();
    vabc.set(..)   // populate vabc object 

    ObjectFactory of = new ObjectFactory();
    JAXBElement<ABC> jabc = of.createABC(vabc);
    ABC oabc = jabc .getValue();

编组器代码 -

Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setContextPath("com.pkg.wsdl");

并调用后端 Web 服务 -

        ABCResp response = (ABCResp) getWebServiceTemplate()
        .marshalSendAndReceive("http://host:port/svcname",oabc);

有以下我必须解决的问题 -
1- 缺少 xmlRootElement 注释错误
必须在 marshalSendAndReceive 中传递 JAXBElement 本身,如下所示。
您可以从 ObjectFactory 中提取 QName 的确切详细信息。

2- 请求错误中缺少 soapAction
必须通过如下所示的 WebServiceMessageCallback 函数来设置 soapAction

3- classCastExcetion 解组响应
必须添加 JAXBIntrospector 来修复此错误

ABCResp response = (ABCResp ) JAXBIntrospector.getValue(getWebServiceTemplate()
        .marshalSendAndReceive(
                "http://host:port/svcname",
                new JAXBElement<ABC>(new QName(uri, localpart),ABC.class,request),
                new WebServiceMessageCallback() {

                    public void doWithMessage(WebServiceMessage message) {
                        ((SoapMessage)message).setSoapAction("/test");
                    }
                }));