Enterprise JavaBean 專案(EJB 2.0 至 EJB 2.1)

J2EE 移轉精靈支援將 Enterprise Bean 部署描述子從 J2EE 1.3 規格層次的 EJB 資源移轉至 J2EE 1.4。Stateless Session Bean 和訊息驅動 Bean 都會移轉至 J2EE 1.4。

移轉 Session Bean

J2EE 移轉精靈會在 Stateless Session Bean 設定服務端點介面,以將在 J2EE 1.3 EJB 專案的 webservices.xml 描述子中定義成服務端點介面 (SEI) 的 Stateless Session Bean 移轉至 J2EE 1.4 規格層次。

如果 Session Bean 是當成 Web 服務端點使用,J2EE 1.4 規格便需要一個定義在 Stateless Session Bean 的 SEI。在 EJB JAR 檔的移轉期間,EJB 專案中的所有 Session Bean 都會使服務端點設為 EJB 專案之 webservices.xml 描述子中所用的名稱。以下是在移轉至 J2EE 1.4 規格層次之前和之後,EJB 專案的 Meta 資料內容範例。

J2EE 1.3 EJB 專案:在移轉之前,以 Stateless Session Bean 為 Web 服務端點介面的 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>
在移轉之前,上述範例中的 <service-endpoint-interface><service-impl-bean> 標示將 Stateless Session Bean "EchoEJB" 定義成 J2EE 1.3 規格層次之 Web 服務描述子中的服務端點。

J2EE 1.4 EJB 專案:相同 Stateless Session Bean "EchoEJB" 的 EJB 部署描述子,含有移轉程序所建立的服務端點介面

<?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 到 EJB 2.1 訊息驅動 Bean 的移轉作業。

訊息驅動 Bean 是在 EJB 2.0 引進,用來支援處理來自 Java™ 傳訊服務 (JMS) 的非同步訊息。EJB 2.1 規格擴充了訊息驅動 Bean 的定義,使它能夠支援任何傳訊系統,而不只是 JMS。

註: 已從 EJB 2.0 規格層次移轉到 EJB 2.1 且部署到 WebSphere Application Server 第 6 版的訊息驅動 Bean,必須對 Java Connector Architecture (JCA) 1.5 資源配接器部署,而非對接聽器埠部署(如同在 WebSphere Application Server 第 5 版中一樣)。您必須使用「部署描述子編輯器」來變更 EJB 2.1 訊息驅動 Bean 的「WebSphere 連結」設定,以使用 JCA 配接器。請參閱配置 EJB 2.1 訊息驅動 Bean 以使用 JCA 配接器
移轉的 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>
相關工作
配置 EJB 2.1 訊息驅動 Bean 以使用 JCA 配接器
相關參考
Web 專案(Servlet 層次 2.3 至 Servlet 層次 2.4)
連接器專案(JCA 1.0 至 JCA 1.5)
Web 服務(J2EE 1.3 至 J2EE 1.4)
J2EE 1.3 至 1.4 規格層次移轉
意見
(C) Copyright IBM Corporation 2000, 2005. All Rights Reserved.