配置 JCA Connection Factory
您可以配置遵守 Java™ EE 連接器架構 (JCA) 規格的 Connection Factory。
關於這項作業
註: 如果要配置 Liberty 的 JCA 支援,您必須使用 WebSphere® Application Server Developer Tools for Eclipse 的「伺服器配置」編輯器的「程式碼」視圖,或是其他文字編輯器,來編輯 server.xml 檔。此主題假設已在伺服器中配置唯一 ID 為 MyAdapter 的資源配接器,請參閱有關配置資源配接器的說明文件,以取得進一步的詳細資料。下列步驟中有提供配置基本實務範例的端對端範例。
註: 不支援在 WebSphere® Development Tools (WDT) 的「設計」視圖中,針對 Connection Factory、管理物件、啟動規格和資源配接器,編輯伺服器配置的內容子元素。
程序
範例
使用下列範例來了解,如何以具有唯一介面類別名稱的兩個 Connection Factory,來配置資源配接器。
在 ra.xml 檔案的下列 Snippet 中,MyAdapter 資源配接器提供具有唯一介面類別名稱的兩個 Connection Factory:
<connection-definition>
<config-property>
<config-property-name>ServerName</config-property-name>
<config-property-type>java.lang.String</config-property-type>
</config-property>
<connectionfactory-interface>javax.resource.cci.ConnectionFactory</connectionfactory-interface>
<connectionfactory-impl-class>com.vendor.adapter.ConnectionFactoryImpl</connectionfactory-impl-class>
</connection-defintion>
<connection-definition>
<config-property>
<config-property-name>ServerName</config-property-name>
<config-property-type>java.lang.String</config-property-type>
</config-property>
<connectionfactory-interface>javax.sql.DataSource</connectionfactory-interface>
<connectionfactory-impl-class>com.vendor.adapter.DataSourceImpl</connectionfactory-impl-class>
</connection-defintion>
以下是適用於此實務的伺服器配置範例:<connectionFactory jndiName="eis/cf">
<properties.MyAdapter.ConnectionFactory serverName="localhost"/>
</connectionFactory>
<connectionFactory jndiName="jdbc/ds">
<properties.MyAdapter.DataSource serverName="localhost"/>
</connectionFactory>
使用下列範例來了解,如何以具有唯一實作類別名稱的兩個 Connection Factory,來配置資源配接器。
在 ra.xml 檔案的下列 Snippet 中,MyAdapter 資源配接器提供具有唯一實作類別名稱的兩個 Connection Factory:
<connection-definition>
<config-property>
<config-property-name>ServerName</config-property-name>
<config-property-type>java.lang.String</config-property-type>
</config-property>
<connectionfactory-interface>javax.resource.cci.ConnectionFactory</connectionfactory-interface>
<connectionfactory-impl-class>com.vendor.adapter.ConnectionFactoryImpl</connectionfactory-impl-class>
</connection-defintion>
<connection-definition>
<config-property>
<config-property-name>ServerName</config-property-name>
<config-property-type>java.lang.String</config-property-type>
</config-property>
<connectionfactory-interface>com.vendor.adapter.ConnectionFactory</connectionfactory-interface>
<connectionfactory-impl-class>com.vendor.adapter.MyConnectionFactoryImpl</connectionfactory-impl-class>
</connection-defintion>
以下是適用於此實務的伺服器配置範例:<connectionFactory jndiName="eis/cf1">
<properties.MyAdapter.ConnectionFactoryImpl serverName="localhost"/>
</connectionFactory>
<connectionFactory jndiName="eis/cf2">
<properties.MyAdapter.MyConnectionFactoryImpl serverName="localhost"/>
</connectionFactory>
使用下列範例來了解,如何以簡式介面和實作類別名稱都不是唯一的兩個 Connection Factory,來配置資源配接器。
在 ra.xml 檔案的下列 Snippet 中,MyAdapter 資源配接器提供兩個 Connection Factory,其中簡式介面和實作類別名稱都不是唯一的:
<connection-definition>
<config-property>
<config-property-name>ServerName</config-property-name>
<config-property-type>java.lang.String</config-property-type>
</config-property>
<connectionfactory-interface>javax.resource.cci.ConnectionFactory</connectionfactory-interface>
<connectionfactory-impl-class>com.vendor.adapter.ConnectionFactoryImpl</connectionfactory-impl-class>
</connection-defintion>
<connection-definition>
<config-property>
<config-property-name>HostName</config-property-name>
<config-property-type>java.lang.String</config-property-type>
</config-property>
<connectionfactory-interface>com.vendor.adapter.custom.ConnectionFactory</connectionfactory-interface>
<connectionfactory-impl-class>com.vendor.adapter.custom.ConnectionFactoryImpl</connectionfactory-impl-class>
</connection-defintion>
以下是適用於此實務的伺服器配置範例:<connectionFactory jndiName="eis/cci-cf">
<properties.MyAdapter.javax.resource.cci.ConnectionFactory serverName="localhost"/>
</connectionFactory>
<connectionFactory jndiName="eis/custom-cf">
<properties.MyAdapter.com.vendor.adapter.custom.ConnectionFactory hostName="localhost"/>
</connectionFactory>
您可以置換配置元素名稱的字尾。請參閱自訂 JCA 配置元素的相關資訊,以了解如何置換配置元素名稱的字尾。