我们可以在EJB 3.0中使用ejb-jar.xml而不是MessageDrivenBean(MDB)的注释吗?

时间:2012-01-21 07:33:22

标签: ejb ejb-3.0 jboss6.x message-driven-bean

我在EJB 3.0中使用@ActivationConfigProperty配置了消息目标类型,名称等,但我想在EJB 2.0中使用部署描述符(MDB)配置ejb-jar.xml。 / p>

仅供参考:我正在使用JBoss 6

有人可以指导我吗?

2 个答案:

答案 0 :(得分:7)

谢谢你,但我以更简单的方式想出来了。以下是代码

<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>

答案 1 :(得分:5)

以下是用于配置MDB的xml内容,可以相应地修改以下代码。

<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>