Enterprise JavaBean 项目(EJB 2.0 到 EJB 2.1)

J2EE 迁移向导支持将企业 bean 部署描述符从 J2EE 1.3 规范级别 EJB 资源迁移到 J2EE 1.4。将无状态会话 bean 和消息驱动的 Bean 迁移到 J2EE 1.4。

迁移会话 bean

通过对无状态会话 bean 设置服务端点接口,J2EE 迁移向导将 J2EE 1.3 中的 EJB 项目的 webservices.xml 描述符中定义为服务端点接口(SEI)的无状态会话 bean 迁移到 J2EE 1.4 规范级别。

如果要将无状态会话 bean 用作 Web Service 端点,则 J2EE 1.4 规范需要对该会话 bean 定义 SEI。在迁移 EJB JAR 文件期间,EJB 项目中的所有会话 bean 都将获得服务端点,该服务端点被设置为在 EJB 项目的 webservices.xml 描述符中使用的名称。以下是在迁移到 J2EE 1.4 规范级别前后 EJB 项目的元数据的外观的示例。

J2EE 1.3 中的 EJB 项目:迁移前将无状态会话 bean 用作 Web Service 端点接口的 webservices.xml 描述符

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE webservices PUBLIC "-//IBM Corporation, Inc.//DTD J2EE Web services 1.0//EN"
"http://www.ibm.com/webservices/dtd/j2ee_web_services_1_0.dtd">
   <webservices id="WebServices_1084831328093">
      <webservice-description id="WebServiceDescription_1084831328093">
         <webservice-description-name>EchoEJBService</webservice-description-name>
         <wsdl-file>META-INF/wsdl/EchoEJB.wsdl</wsdl-file>
         <jaxrpc-mapping-file>META-INF/EchoEJB_mapping.xml</jaxrpc-mapping-file>
         <port-component id="PortComponent_1084831328103">
            <port-component-name>EchoEJB</port-component-name>
            <wsdl-port id="WSDLPort_1084831328103">
               <namespaceURI>http://test</namespaceURI>
               <localpart>EchoEJB</localpart>
            </wsdl-port>
            <service-endpoint-interface>test.EchoEJB</service-endpoint-interface>
            <service-impl-bean id="ServiceImplBean_1084831328103">
               <ejb-link>EchoEJB</ejb-link>
            </service-impl-bean>
         </port-component>
      </webservice-description>
   </webservices>
前面的示例中,在迁移之前 J2EE 1.3 规范级别的 webservices 描述符中,<service-endpoint-interface><service-impl-bean> 标记将无状态会话 bean“EchoEJB”定义为服务端点。

J2EE 1.4 中的 EJB 项目:相同无状态会话 bean“EchoEJB”的 EJB 部署描述符,该会话 bean 具有由迁移过程创建的服务端点接口

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar>
<ejb-jar id="ejb-jar_ID" version="2.1" xmlns="http://java.sun.com/xml/ns/j2ee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    
 xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd">
	<display-name>
	EchoEJBProject</display-name>
	<enterprise-beans>
		<session id="EchoEJB">
			<ejb-name>EchoEJB</ejb-name>
			<home>test.EchoEJBHome</home>
			<remote>test.EchoEJB</remote>
			<service-endpoint>test.EchoEJB</service-endpoint>
			<ejb-class>test.EchoEJBBean</ejb-class>
			<session-type>Stateless</session-type>
			<transaction-type>Container</transaction-type>
		</session>
	</enterprise-beans>
</ejb-jar>
前面示例中的 <service-endpoint> 标记将“EchoEJB”定义为迁移之后 J2EE 1.4 规范级别中的服务端点。

迁移消息驱动的 bean

J2EE 迁移向导支持将 EJB 2.0 消息驱动的 Bean 迁移到 EJB 2.1 Java™ 消息服务(JMS)类型消息驱动的 Bean。

EJB 2.0 中引进了消息驱动的 Bean 以支持处理来自 Java 消息服务(JMS)的异步消息。EJB 2.1 规范扩展了消息驱动的 Bean 的定义,以便它不仅可以支持 JMS,还可以支持任何消息传递系统。

迁移的 EJB 2.0 消息驱动的 Bean 构件是:
  • acknowledgeMode
  • messageSelector
  • destinationType
  • subscriptionDurablity
某些 EJB 2.0 消息驱动的 Bean 元素被替换为 activation-config 属性。根据所使用的消息服务的类型,activation-config 属性中用来描述消息传递服务的属性名和值将会有所变化。但是,EJB 2.1 为基于 JMS 的消息驱动的 bean 定义了一组固定属性。

下列示例将 EJB 2.0 中样本 bean 的元素与 EJB 2.1 中元素的外观进行比较。

EJB 2.0 中消息驱动的 bean 元素的示例:

<message-driven id="Mdb20">
	  <ejb-name>Mdb</ejb-name>
	  <ejb-class>ejbs.MdbBean</ejb-class>
	  <transaction-type>Bean</transaction-type>
	  <message-selector>mdbMessage</message-selector>
	  <acknowledge-mode>Auto-acknowledge</acknowledge-mode>
	  <message-driven-destination>
		<destination-type>javax.jms.Topic</destination-type>
		<subscription-durability>Durable</subscription-durability>
	   </message-driven-destination>
</message-driven>

EJB 2.1 中消息驱动的 bean 元素的示例:

    <message-driven id="Mdb21">
  <ejb-name>Foo/ejb-name>
  <ejb-class>ejbs.FooBean</ejb-class>
   <messaging-type>javax.jms.MessageListener</messaging-type>
   <transaction-type>Bean/transaction-type>
   <message-destination-type>javax.jms.Topic</message-destination-type>
    <activation-config>
	  <activation-config-property>
	   <activation-config-property-name>destinationType</activation-config-property-name>
	   <activation-config-property-value>javax.jms.Topic</activation-config-property-value>
	  </activation-config-property>
	  <activation-config-property>
	   <activation-config-property-name>subscriptionDurability</activation-config-property-name>
	     <activation-config-property-value>Durable</activation-config-property-value>
	  </activation-config-property>
	  <activation-config-property>
	     <activation-config-property-name>acknowledgeMode</activation-config-property-name>
	     <activation-config-property-value>AutoAcknowledge</activation-config-property-value>
	  </activation-config-property>
	  <activation-config-property>
		<activation-config-property-name>messageSelector</activation-config-property-name>
		<activation-config-property-value>fooSelector</activation-config-property-value>
	  </activation-config-property>
</activation-config>
</message-driven>
相关参考
Web 项目(Servlet 级别 2.3 到 Servlet 级别 2.4)
连接器项目(JCA 1.0 到 JCA 1.5)
Web Service(J2EE 1.3 到 J2EE 1.4)
J2EE 1.3 到 1.4 规范级别迁移
使用条款 | 反馈
(C) Copyright IBM Corporation 2000, 2005. All Rights Reserved.