JAXB 编组异常;嵌套异常是 javax.xml.bind.MarshalException

JAXB marshalling exception; nested exception is javax.xml.bind.MarshalException

我正在从文件中读取数据并验证数字并调用 webservice.I 我在调用 webservice 时遇到以下错误。

[org.springframework.integration.ws.MarshallingWebServiceOutboundGateway] org.springframework.integration.ws.MarshallingWebServiceOutboundGateway#0 received message: GenericMessage [payload=1000213569, headers={timestamp=1432121523488, id=fbdb4e0d-d124-1620-8b41-c8dfea69069c, correlationId=e68bb811-7e9e-b86b-0b28-c24a2e3c02c0, sequenceSize=0, sequenceNumber=2}]
14:32:03.488 DEBUG [task-scheduler-1][org.springframework.integration.transformer.MessageTransformingHandler] org.springframework.integration.transformer.MessageTransformingHandler@7f422265 received message: ErrorMessage [payload=org.springframework.messaging.MessageHandlingException: error occurred in message handler [org.springframework.integration.ws.MarshallingWebServiceOutboundGateway#0]; nested exception is org.springframework.oxm.MarshallingFailureException: JAXB marshalling exception; nested exception is javax.xml.bind.MarshalException
 - with linked exception:
[com.sun.istack.internal.SAXException2: unable to marshal type "java.lang.String" as an element because it is missing an @XmlRootElement annotation], headers={timestamp=1432121523488, id=1cf537f4-0789-d188-2563-6d5aab55b942}]
14:32:03.488 DEBUG [task-scheduler-1][org.springframework.integration.file.FileWritingMessageHandler] org.springframework.integration.file.FileWritingMessageHandler@4ee05628 received message: GenericMessage [payload=org.springframework.messaging.MessageHandlingException: error occurred in message handler [org.springframework.integration.ws.MarshallingWebServiceOutboundGateway#0]; nested exception is org.springframework.oxm.MarshallingFailureException: JAXB marshalling exception; nested exception is javax.xml.bind.MarshalException
 - with linked exception:

任何人都可以帮我解决这个异常。

这是我的上下文文件:

   <int-sftp:inbound-channel-adapter id="sftpAdapterAutoCreate"
          session-factory="sftpSessionFactory" filename-pattern="*.*"
          remote-directory="/testSFTP/inbox/" local-directory="file:input"
          auto-create-local-directory="true" auto-startup="true"
          delete-remote-files="false" local-filename-generator-expression="#this"
          temporary-file-suffix=".writing">
          <int:poller fixed-delay="60000" max-messages-per-poll="10" />
   </int-sftp:inbound-channel-adapter>

   <int:splitter input-channel="sftpAdapterAutoCreate"
          output-channel="routingChannel"
          expression="T(org.apache.commons.io.FileUtils).lineIterator(payload)" />


   <int:channel id="routingChannel" />

   <int:filter input-channel="routingChannel" output-channel="routingChannel2" discard-channel="errorChannel"
          id="validateFormat" method="accept" ref="NinValidatorClass">       </int:filter>

   <int:channel id="routingChannel2"/>

   <int:channel id="errorChannel" >
   </int:channel>

   <int:transformer
          expression="payload"
          output-channel="routingChannel3" auto-startup="true" input-channel="routingChannel2" />

          <int:transformer
          expression="payload?.toString()"
          output-channel="errorChannel2" auto-startup="true" input-channel="errorChannel" />

   <int:channel id="routingChannel3">
   <int:interceptors>
   <int:wire-tap channel="loggingChannel"/>
   </int:interceptors>
   </int:channel>

   <int:channel id="errorChannel2"/>


   <int-file:outbound-channel-adapter channel="wsResponseChannel"
          id="filesOut" auto-create-directory="true" directory="file:target/output"
          filename-generator-expression="'nins.txt.completed'" mode="APPEND"></int-file:outbound-channel-adapter>


   <int-file:outbound-channel-adapter channel="errorChannel2"
          id="errorOut" auto-create-directory="true" directory="file:target/output"
          filename-generator-expression="'nins.txt.error'" mode="APPEND"></int-file:outbound-channel-adapter>

   <!--  -->
   <int:channel id="wsResponseChannel" />

 <int-ws:outbound-gateway id="ws-gateway" uri="http://localhost:8080/ws/WS/RetriveCitizenInfo"  request-channel="routingChannel3" reply-channel="wsResponseChannel"
      marshaller="marshaller" unmarshaller="marshaller"> 
 </int-ws:outbound-gateway>

 <oxm:jaxb2-marshaller id="marshaller"  context-path="agenciesWs.wsdl"/>

unable to marshal type "java.lang.String" as an element because it is missing an @XmlRootElement annotation],

因此,您的 payload 是字符串,但是 marshaller 需要一个在 class.

上带有该注释的域 Java Bean

否则,如果您的字符串有效 XML,请尝试在没有 marshaller 的情况下使用 <int-ws:outbound-gateway>