我正在使用 Spring Boot 来调用 Web 服务。
我的配置类是:
@Configuration
public class ClientAppConfig {
@Bean
public Jaxb2Marshaller marshaller() {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setPackagesToScan("com.client.stub");
return marshaller;
}
@Bean
public ARTestClient arTestClient(Jaxb2Marshaller marshaller) {
ARTestClient client = new ARTestClient();
client.setDefaultUri("uri");
client.setMarshaller(marshaller);
client.setUnmarshaller(marshaller);
return client;
}
我正在调用服务如下:
OutputMessageType response = (OutputMessageType) getWebServiceTemplate().marshalSendAndReceive(
inputMessageType, new SoapActionCallback("http://Serviceuri"));
我收到以下错误:
[2016-03-18 14:45:43.697] boot - 10272 ERROR [http-nio-8080-exec-1] --- [dispatcherServlet]: Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception
[Request processing failed; nested exception is java.lang.ClassCastException: javax.xml.bind.JAXBElement
cannot be cast to com.wfs.client.stub.ar.OutputMessageType] with root cause
如何解码 webservice 的输出????
我如何为响应设置解码器?
最佳答案
有趣的是,我只是遇到了同样的问题,这就是我所做的:
将您的回复转换到
JAXBElement<OutputMessageType>
所以结果是
JAXBElement<OutputMessageType> response = (JAXBElement<OutputMessageType>) getWebServiceTemplate().marshalSendAndReceive(
inputMessageType, new SoapActionCallback("http://Serviceuri"));
// Then just call
System.out.println(response.getValue());
我的配置和你差不多。我仍在试图弄清楚为什么会出现 ClassCastException。至少我们有一个解决方法......
关于spring - java.lang.ClassCastException : javax. xml.bind.JAXBElement 无法转换为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36088010/