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.