配置 JCA Connection Factory

您可以配置遵守 Java™ EE 連接器架構 (JCA) 規格的 Connection Factory。

關於這項作業

您可以針對由所安裝之資源配接器提供的 Connection Factory 類型,配置一或多個 Connection Factory 實例。
註: 如果要配置 Liberty 的 JCA 支援,您必須使用 WebSphere® Application Server Developer Tools for Eclipse 的「伺服器配置」編輯器的「程式碼」視圖,或是其他文字編輯器,來編輯 server.xml 檔。此主題假設已在伺服器中配置唯一 ID 為 MyAdapter 的資源配接器,請參閱有關配置資源配接器的說明文件,以取得進一步的詳細資料。下列步驟中有提供配置基本實務範例的端對端範例。
註: 不支援在 WebSphere® Development Tools (WDT) 的「設計」視圖中,針對 Connection Factory、管理物件、啟動規格和資源配接器,編輯伺服器配置的內容子元素。

程序

  1. 更新 server.xml 檔案,在 featureManager 標籤底下新增 jca-1.6 特性。
    <featureManager>  
    	<feature>jca-1.6</feature> 
    	<feature>jndi-1.0</feature>  <!-- 新增 jndi 特性來啟用查閱 Connection Factory 和受管理物件。-->   
    		... 
    </featureManager>
  2. 安裝資源配接器。 例如,更新 server.xml 檔案,如下所示:
    <resourceAdapter location="C:/adapters/MyAdapter.rar"/>
  3. 配置一或多個 Connection Factory 實例。 當您配置 Connection Factory 實例時,即使不想置換任何配置內容,也必須提供 properties 子元素,以將 connectionFactory 元素與特定資源配接器提供的 Connection Factory 介面建立關聯。在下列範例中,MyAdapter 資源配接器只提供一種 Connection Factory 類型:
    <connectionFactory jndiName="eis/cf1">
     <properties.MyAdapter portNumber="1234" someVendorProperty="100"/>
    </connectionFactory>
    
    <connectionFactory jndiName="eis/cf2" containerAuthDataRef="auth2">
     <connectionManager maxPoolSize="20" connectionTimeout="0"/>
     <properties.MyAdapter portNumber="1234" someVendorProperty="200"/>
    </connectionFactory>
    <authData id="auth2" user="user2" password="{xor}Lz4sLCgwLTtt"/>
  4. (選用)若有需要,請識別可用的 Connection Factory 內容子元素名稱。
    • 如果資源配接器提供正好一個 Connection Factory 介面(不包括任何 JMS Connection Factory),則子元素是:properties.<rar_identifier>

    • 如果介面名稱是唯一的,且沒有套件名稱,則子元素名稱是:properties.<rar_identifier>.<InterfaceName>
    • 如果實作名稱是唯一的,且沒有套件名稱,則子元素名稱是:properties.<rar_identifier>.<ImplementationName>
    • 在其他情況下,子元素名稱是:properties.<rar_identifier>.<fully.qualified.InterfaceName>

範例

使用下列範例來了解,如何以具有唯一介面類別名稱的兩個 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 配置元素的相關資訊,以了解如何置換配置元素名稱的字尾。

指示主題類型的圖示 作業主題

檔名:twlp_jca_config_confact.html