Spring JMS模板发送无效消息

时间:2014-05-30 22:24:26

标签: java spring marshalling spring-jms

我在使用Spring JMSTemplate来编组和发送JMS消息时遇到了问题。一切都正确发送,但当我尝试查看队列中的消息时,似乎消息的正文文本都是乱码。我不确定在我的设置中哪些地方可能有问题...我使用的方法之前使用的方法我发送过消息。有没有人看过这个?

这是邮件正文发送后的一个代码段: 00000000: 3c3f 786d 6c20 7665 7273 696f 6e3d 2231 .?xml version."1 00000010: 2e30 2220 656e 636f 6469 6e67 3d22 5554 .0" encoding."UT 00000020: 462d 3822 2073 7461 6e64 616c 6f6e 653d F.8" standalone. 00000030: 2279 6573 223f 3e3c 7072 6f64 7563 7445 "yes"?..productE

我的模板和marshaller设置如下:                                     

<!-- Non-pooled ConnectionFactory, don't use directly -->
<jee:jndi-lookup id="jmsFactory" jndi-name="${jms.connectionFactory}"/>

<!-- JMS Destinations -->
<jee:jndi-lookup id="emfTopic" jndi-name="${emf.topic.jndiPath}"/>

<!-- JMS Template for sending JMS Messages -->
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
    <property name="connectionFactory" ref="connectionFactory"/>
    <property name="messageConverter" ref="messageConverter"/>
</bean>

<!-- A converter that marshalls/unmarshalls XML messages -->
<bean id ="messageConverter" class="org.springframework.jms.support.converter.MarshallingMessageConverter">
    <property name="marshaller" ref="jaxbMarshaller"/>
    <property name="unmarshaller" ref="jaxbMarshaller"/>
</bean>

<!-- JAXB Marshaller for JMS Messages -->
<bean id="jaxbMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
    <property name="classesToBeBound">
        <list>...`

我正在发送这样的消息: EmfMessagePostProcessor postProcess = new EmfMessagePostProcessor(true, hasId);

//Convert the message, set properties, then send
jmsTemplate.convertAndSend(this.emfTopic, theMessage, postProcess);`

非常感谢有关此问题的任何帮助!

1 个答案:

答案 0 :(得分:1)

Stéphane的评论是问题所在。我没有明确地将targetType设置为TextMessage,因此它作为byteMessage发送,因为这是默认值。更改targetType修复了问题。