JAXB由于缺少@xmlrootelement注释而从WSDL无法解散请求生成代码
我使用此手动生成用于在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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论