0

XML構成の使用 - 私はMarshallingMessageConverter働いています。TextMessageただし、単純な値と同じようにいくつかのメッセージを送信したいと考えていStringます。

私の構成では、ある溝 (自動 JAXB マーシャリングなし) から別の溝 (JAXB マーシャリングのみ) に移動する必要があるようです。

関連する XML 構成は次のとおりです。

<bean id="jaxbConverter" class="org.springframework.jms.support.converter.MarshallingMessageConverter">
    <property name="marshaller" ref="jaxb2Marshaller" />
    <property name="unmarshaller" ref="jaxb2Marshaller" />
</bean>

<bean id="jmsListenerContainerFactory"
      class="org.springframework.jms.config.DefaultJmsListenerContainerFactory">
    <property name="errorHandler" ref="jmsErrorHandler" />
    <property name="connectionFactory" ref="connectionFactory"/>
    <property name="destinationResolver" ref="jmsDestinationResolver"/>
    <property name="messageConverter" ref="jaxbConverter" />
</bean>

JAXB マーシャリングは正常に機能しますが、空の本文 (ヘッダー プロパティのみ) のメッセージを送信したい場合があります。次のようなエラーが発生します。

.UnmarshallingFailureException: JAXB unmarshalling exception; nested exception is javax.xml.bind.UnmarshalException
 - with linked exception:
[org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.]

本文で非 JAXB 文字列 (または何も送信しない) を送信しているため、これは理にかなっています。

両方の長所を活かすことは可能ですか? , String, -and-byte[]Map変換動作org.springframework.jms.support.converter.SimpleMessageConverterorg.springframework.jms.support.converter.MarshallingMessageConverter

他のコンバーターで 2 番目のコンテナー ファクトリを作成し、それを@JmsListener注釈で明示的に使用することによって、これを達成する唯一の方法はありますか?

4

1 に答える 1

2

単純なDelegatingMessageConverter(実装) を作成し、メッセージ プロパティ (例: - 、 )に基づいて、(または)MessageConverterに委任します。SimpleMessageConverterMarshallingMessageConverterMappingJackson2MessageConvertermessage.getStringProperty("contentType")text/plainapplication/xmlapplication/json

于 2016-01-30T14:52:17.557 に答える