2

我有简单的消息驱动 Bean

@Named
@MessageDriven(mappedName = "jms/myQueue")
public class TestMDB implements MessageListener {

  @Override
  public void onMessage(Message msg) {
     //...
  }
}

如何仅使用部署描述符 ejb-jar.xml 而不是注释来实现相同的效果?我在编译时不知道队列的 JNDI 名称,所以我想在部署描述符中指定它。

4

1 回答 1

0

也许类似于:

    <message-driven>
        <ejb-name>TestMDB</ejb-name>
        <ejb-class>package.name.TestMDB</ejb-class>
        <messaging-type>javax.jms.MessageListener</messaging-type>
        <transaction-type>Container</transaction-type>
        <message-destination-type>javax.jms.Queue</message-destination-type>        
        <activation-config>
           <activation-config-property>
              <activation-config-property-name>destination</activation-config-property-name>
              <activation-config-property-value>myQueue</activation-config-property-value>
           </activation-config-property>
           <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-property>
              <activation-config-property-name>acknowledgeMode</activation-config-property-name>
              <activation-config-property-value>Auto-acknowledge</activation-config-property-value>
           </activation-config-property>
        </activation-config>
        <resource-ref id="ResourceRef_0">
           <res-ref-name>jms/myQCF</res-ref-name>
           <res-type>javax.jms.QueueConnectionFactory</res-type>
           <res-auth>Application</res-auth>
           <res-sharing-scope>Shareable</res-sharing-scope>
        </resource-ref>
     </message-driven>

然后在 bnd.xml 文件中:

<message-driven name="TestMDB">
    <jca-adapter activation-spec-binding-name="mdb30/myQueue" destination-binding-name="Jetstream/jms/myQueue" activation-spec-auth-alias=""/>
    <resource-ref name="jms/myQCF" binding-name="Jetstream/jms/myQCF"/>
</message-driven>
于 2015-03-12T19:27:11.183 回答