我有以下代码配置为使用Spring框架和ActiveMQ作为代理发送JMS消息 . 但是当我尝试将消息发送到目标队列时,我得到了以下异常 . 事情是,如果我更改“jmsTemplate " connectionFactory to " amqConnectionFactory”ActiveMQ连接工厂,它可以工作(没有例外) . 但是,这不会破坏使用Spring缓存连接的目的吗?

知道我做错了什么吗?

Exception

org.springframework.jms.InvalidDestinationException: Queues are not supported by a TopicSession; nested exception is javax.jms.InvalidDestinationException: Queues are not supported by a TopicSession

Spring Config

<!-- A connection to ActiveMQ -->
<bean id="amqConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
    <property name="brokerURL">
        <value>tcp://localhost:61616</value>
    </property>
</bean>

<!-- a cache/pooling based JMS provider -->
<bean id="cachedConnectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
    <constructor-arg name="targetConnectionFactory" ref="amqConnectionFactory" />
    <property name="sessionCacheSize" value="5" />
</bean>

<bean id="requestQueue" class="org.apache.activemq.command.ActiveMQQueue">
    <constructor-arg value="EMS_QUEUE" />
</bean>

<!-- Spring JMS Template -->
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
    <property name="connectionFactory" ref="cachedConnectionFactory" />
</bean>

<bean id="dataWriterService" class="com.beneris.ems.commons.service.impl.JmsDataWriterService">
    <constructor-arg name="jmsTemplate" ref="jmsTemplate" />
    <constructor-arg name="destination" ref="interrogationDataQueue" />
    <property name="jmsType" value="EMS.DATA.RAW" />
</bean>

Java Code

public class JmsDataWriterService implements DataWriterService {

private JmsTemplate jmsTemplate;
private Destination destination;
private String jmsType;

public JmsDataWriterService(JmsTemplate jmsTemplate, Destination destination) {
    this.jmsTemplate = jmsTemplate;
    this.destination = destination;
}

public void setJmsType(String jmsType) {
    this.jmsType = jmsType;
}

@Override
public void write(String payload) {
    jmsTemplate.send(destination, new MessageCreator() {

        @Override
        public Message createMessage(Session session) throws JMSException {
            TextMessage msg = session.createTextMessage(payload);
            msg.setJMSCorrelationID(Utils.createGuid());
            if(jmsType != null)
                msg.setJMSType(jmsType);
            return msg;
        }
    });
}

@Override
public void write(byte[] payload) {
    jmsTemplate.send(destination, new MessageCreator() {   //throws the EXCEPTION here !!!

        @Override
        public Message createMessage(Session session) throws JMSException {
            BytesMessage msg = session.createBytesMessage();
            msg.writeBytes(payload);
            msg.setJMSCorrelationID(Utils.createGuid());
            if(jmsType != null)
                msg.setJMSType(jmsType);
            return msg;
        }
    });
}

}