JAXB由于缺少@xmlrootelement注释而从WSDL无法解散请求生成代码

发布于 2025-02-03 17:41:37 字数 1933 浏览 3 评论 0原文

我使用此手动生成用于在Springboot Project中调用SOAP WebService的代码使用不同的WSDL文件。

我将生成的源复制到项目的“ util.pbn”软件包中,但是当我运行程序时,我会面对此例外:

com.sun.istack.SAXException2: unable to marshal type "util.pbn.RateRequest" as an element because it is missing an @XmlRootElement annotation
at org.springframework.oxm.jaxb.Jaxb2Marshaller.convertJaxbException(Jaxb2Marshaller.java:948) ~spring-oxm-5.3.20.jar:5.3.20
at org.springframework.oxm.jaxb.Jaxb2Marshaller.marshal(Jaxb2Marshaller.java:713) ~spring-oxm-5.3.20.jar:5.3.20
at org.springframework.ws.support.MarshallingUtils.marshal(MarshallingUtils.java:79) ~spring-ws-core-3.1.3.jar:na
at org.springframework.ws.client.core.WebServiceTemplate$2.doWithMessage(WebServiceTemplate.java:402) ~spring-ws-core-3.1.3.jar:na
at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:572) ~spring-ws-core-3.1.3.jar:na
at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:542) ~spring-ws-core-3.1.3.jar:na
at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:394) ~spring-ws-core-3.1.3.jar:na
at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:383) ~spring-ws-core-3.1.3.jar:na
... 5 common frames omitted

在我生成的代码中,没有XMLrootelemet集,但是我的'util.pbn'软件包中有一个完整的objectfactory。我使用此代码块来配置邮政书机,但似乎JAX2Marshaler不了解ObjectFactory类。

@Bean
public Jaxb2Marshaller marshaller() {
    Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
    marshaller.setContextPath("util.pbn");
    return marshaller;
}

我不知道为什么jaxb2marshaller dos不使用objectfactory类并坚持使用@xmlrootelement注释?我应该如何配置我的项目为JAX2BMARSHALLER设置对象图?

PS:在发布此问题之前,我已经搜索了Stackoverflow,但是它们的解决方案都不适合我。

I use this manual to generate code for calling soap webservice in a Springboot project with a different wsdl file.

I copy generated source into 'util.pbn' package of my project but when I run my program I face to this exception:

com.sun.istack.SAXException2: unable to marshal type "util.pbn.RateRequest" as an element because it is missing an @XmlRootElement annotation
at org.springframework.oxm.jaxb.Jaxb2Marshaller.convertJaxbException(Jaxb2Marshaller.java:948) ~spring-oxm-5.3.20.jar:5.3.20
at org.springframework.oxm.jaxb.Jaxb2Marshaller.marshal(Jaxb2Marshaller.java:713) ~spring-oxm-5.3.20.jar:5.3.20
at org.springframework.ws.support.MarshallingUtils.marshal(MarshallingUtils.java:79) ~spring-ws-core-3.1.3.jar:na
at org.springframework.ws.client.core.WebServiceTemplate$2.doWithMessage(WebServiceTemplate.java:402) ~spring-ws-core-3.1.3.jar:na
at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:572) ~spring-ws-core-3.1.3.jar:na
at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:542) ~spring-ws-core-3.1.3.jar:na
at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:394) ~spring-ws-core-3.1.3.jar:na
at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:383) ~spring-ws-core-3.1.3.jar:na
... 5 common frames omitted

In my generated code, no xmlrootelemet set but there is a complete ObjectFactory in my 'util.pbn' package. I use this block of code to config marshaller but it seems jax2marshaler is not aware of ObjectFactory class.

@Bean
public Jaxb2Marshaller marshaller() {
    Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
    marshaller.setContextPath("util.pbn");
    return marshaller;
}

I don't know why jaxb2marshaller dosn't use ObjectFactory class and insists to use @XmlRootElement annotation? How I should config my project to set Objectfactory for jax2bmarshaller?

p.s: I've searched stackoverflow before I post this issue, but none of their solution works for me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文