如何在单个MessageListenerContainer中为Spring Java Config添加多个JMS MessageListners

我的spring-config.xml中有以下xml代码

<jms:listener-container acknowledge="auto"
        connection-factory="cachedConnectionFactory" container-type="default"
        error-handler="consumerErrorHandler" concurrency="20-25">
        <jms:listener destination="#{TaskFinished.destination}"
            method="onMessage" ref="taskFinished" />
</jms:listener-container>

现在,我正在将spring xml配置文件转换为Java配置.

我翻译像

@Bean(name = "consumerJmsListenerContainer")
public DefaultMessageListenerContainer consumerJmsListenerContainer() {
    DefaultMessageListenerContainer messageListenerContainer = new DefaultMessageListenerContainer();
    messageListenerContainer
            .setConnectionFactory(cachingConnectionFactory());
    messageListenerContainer.setConcurrency("20-25");
    messageListenerContainer.setErrorHandler(new ConsumerErrorHandler());
    messageListenerContainer
            .setSessionAcknowledgeMode(Session.AUTO_ACKNOWLEDGE);
    messageListenerContainer.setMessageListener(new TaskFinished());
    return messageListenerContainer;
}

我需要知道的是,消息容器中是否有多个MessageListner,例如

<jms:listener-container acknowledge="auto"
        connection-factory="cachedConnectionFactory" container-type="default"
        error-handler="consumerErrorHandler" concurrency="20-25">
        <jms:listener destination="#{questionGeneration.destination}"
            method="onMessage" ref="questionGeneration" />
        <jms:listener destination="#{friendShipLogic.destination}"
            method="onMessage" ref="friendShipLogic" />
        <jms:listener destination="#{postAvailabilityChecker.destination}"
            method="onMessage" ref="postAvailabilityChecker" />
        <jms:listener destination="#{playOn.destination}" method="onMessage"
            ref="playOn" />
</jms:listener-container>

我应该如何将这个xml代码转换为Java配置?

最佳答案
命名空间只是一种便利-每个< jms:listener />元素拥有自己的DMLC;外部(容器)元素只是提供通用属性的工具.

转载注明原文:如何在单个MessageListenerContainer中为Spring Java Config添加多个JMS MessageListners - 代码日志