4

我正在使用 EJB 3.1,我想配置一个 MDB 来监听多个队列。
我更喜欢通过 XML 定义队列名称,但通过注释定义其他定义。
这可以做到吗?

4

2 回答 2

6

实例化后,MDB 只能侦听其目标 ActivationConfigProperty 中指定的资源,但是您可以创建具有不同目标(在您的情况下为队列)的同一 MDB 的多个实例。

在您的 ejb-jar.xml 中创建两个具有不同目标和 ejb-name 属性但相同 ejb-class 的条目。

于 2011-08-24T05:28:53.627 回答
0

使用 ejb-jar.xml 代替 ibm-ejb-jar-bnd.xml

    <message-driven>
        <ejb-name>MessageDrivenBean1</ejb-name>
        <ejb-class>com.sample.MessageDrivenBean</ejb-class>
        <messaging-type>javax.jms.MessageListener</messaging-type>
        <transaction-type>Container</transaction-type>
        <activation-config>
            <activation-config-property>
                <activation-config-property-name>destinationType</activation-config-property-name>
                <activation-config-property-value>javax.jms.Queue</activation-config-property-value>
            </activation-config-property>
        </activation-config>
    </message-driven>

    <message-driven>
        <ejb-name>MessageDrivenBean2</ejb-name>
        <ejb-class>com.sample.MessageDrivenBean</ejb-class>
        <messaging-type>javax.jms.MessageListener</messaging-type>
        <transaction-type>Container</transaction-type>
        <activation-config>
            <activation-config-property>
                <activation-config-property-name>destinationType</activation-config-property-name>
                <activation-config-property-value>javax.jms.Queue</activation-config-property-value>
            </activation-config-property>
        </activation-config>
    </message-driven>

</enterprise-beans>

并从您的 Java 类中删除 @MessageDriven 注释

'@MessageDriven(activationConfig = { @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue")
    })'
于 2018-04-20T20:52:28.607 回答