Can we use ejb-jar.xml instead of annotations for MessageDrivenBean(MDB) in EJB 3.0?

半腔热情 提交于 2019-12-01 18:43:24
Adheep Mohamed Abdul Kader

Thanks man, but I've figured it out in a much simpler way. Below is the code

<ejb-jar id="ejb-jar_ID" version="3.1"
      xmlns="http://java.sun.com/xml/ns/javaee"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
                          http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd">

  <display-name>SampleTransactionMDB</display-name>
  <enterprise-beans>
    <message-driven>
      <display-name>SampleTransactionMDB</display-name>
      <ejb-name>SampleTransactionMDB</ejb-name>
      <ejb-class>com.example.SampleTransactionMDB</ejb-class>
      <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-property>
          <activation-config-property-name>destination</activation-config-property-name>
          <activation-config-property-value>/queue/SampleTransactionQueue</activation-config-property-value>
        </activation-config-property> 
      </activation-config>
    </message-driven>  
  </enterprise-beans>
  <assembly-descriptor>
  </assembly-descriptor>
</ejb-jar>
Nayan Wadekar

Below is the xml content for configuring MDB, can modify the below code accordingly.

<enterprise-beans>
    <message-driven>
        <ejb-name>SomeMessageBean</ejb-name>
        <ejb-class>
            com.bean.SomeMessageBean
        </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-property>
                <activation-config-property-name>destinationType
                </activation-config-property-name>
                <activation-config-property-value>javax.jms.Queue
                </activation-config-property-value>
            </activation-property>
            <activation-property>
                <activation-config-property-name>messageSelector
                </activation-config-property-name>
                <activation-config-property-value>MessageFormat = 'Version 3.4'
                </activation-config-property-value>
            </activation-property>
            <activation-property>
                <activation-config-property-name>acknowledgeMode
                </activation-config-property-name>
                <activation-config-property-value>Auto-acknowledge
                </activation-config-property-value>
            </activation-property>
        </activation-config>

        <resource-ref>
                    <resource-ref-name>jms/ConnectionFactory</resource-ref-name>
                    <resource-type>
                        javax.jms.ConnectionFactory
                    </resource-type>
                        <res-auth>Container</res-auth>
                        <mapped-name>ConnectionFactory</mapped-name>
                        <injection-target>
                            <injection-target-class>
                                com.bean.SomeMessageBean
                            </injection-target-class>
                            <injection-target-name>datasource</injection-target-name>
                        </injection-target>
                </resource-ref>
    </message-driven>
</enterprise-beans>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!