[8.5.5.2 或更新版本]Liberty 儲存庫

配置及部署基本 JCA 資源配接器

您可以配置及部署基本 Java™ EE 連接器架構 (JCA) Connection Factory 和資源配接器。

關於這項作業

您可以安裝資源配接器,並配置其提供的資源實例。此作業會使用一個名為 ExampleRA.rar 的資源配接器範例,其提供 3 種類型的資源:一個 Connection Factory,以及兩種類型的受管理物件。

程序

  1. server.xml 檔案中啟用 JCA 特性。 server.xml 檔案位於 [path_to_liberty\wlp\usr\servers\server_name]
    <server>
      <featureManager>
        <feature>jca-1.6</feature>
        <feature>servlet-3.0</feature>
      </featureManager>
    </server>
  2. 將資源配接器保存檔 (ExampleRA.rar) 放在伺服器的 dropins 資料夾中。 如果您的伺服器正在執行,您會在主控台日誌中看到下列訊息,指出已安裝資源配接器:
    [AUDIT ] J2CA7001I: Resource adapter ExampleRA installed in 1.306 seconds.
  3. 檢查資源配接器的部署描述子、註釋和其他說明文件,以識別配接器提供哪些類型的資源,以及各配接器所接受的配置內容為何。 資源配接器範例 ExampleRA.rar 的 ra.xml 部署描述子中有提供此資訊。ra.xml 檔案位於 [path_to_ExampleRA\ExampleRA\META-INF] 中。部署描述子會識別 3 種您可以配置的資源類型。
    <connection-definition>
     <managedconnectionfactory-class>com.ibm.example.jca.adapter.ManagedConnectionFactoryImpl</managedconnectionfactory-class>
     <config-property>
      <config-property-name>tableName</config-property-name>
      <config-property-type>java.lang.String</config-property-type>
     </config-property>
     <connectionfactory-interface>javax.resource.cci.ConnectionFactory</connectionfactory-interface>
     ...
    </connection-definition>
    
        <adminobject>
          <adminobject-interface>javax.resource.cci.ConnectionSpec</adminobject-interface>
          <adminobject-class>com.ibm.example.jca.adapter.ConnectionSpecImpl</adminobject-class>
          <config-property>
            <config-property-name>readOnly</config-property-name> 
            <config-property-type>java.lang.Boolean</config-property-type>
            <config-property-value>false</config-property-value> 
          </config-property>
        </adminobject>
    
        <adminobject>
          <adminobject-interface>javax.resource.cci.InteractionSpec</adminobject-interface>
          <adminobject-class>com.ibm.example.jca.adapter.InteractionSpecImpl</adminobject-class>
          <config-property>
            <description>Function name. Supported values are: ADD, FIND, REMOVE</description>
            <config-property-name>functionName</config-property-name> 
            <config-property-type>java.lang.String</config-property-type> 
          </config-property>
        </adminobject>
  4. server.xml 檔案中,配置可用資源類型的實例。
    <server>
      <featureManager>
        <feature>jca-1.6</feature>
        <feature>servlet-3.0</feature>
      </featureManager>
    
      <connectionFactory jndiName="eis/conFactory">
        <properties.ExampleRA tableName="TABLE1"/>
      </connectionFactory>
    
      <adminObject jndiName="eis/conSpec">
        <properties.ExampleRA.ConnectionSpec/>
      </adminObject>
    
      <adminObject jndiName="eis/iSpec_ADD">
        <properties.ExampleRA.InteractionSpec functionName="ADD"/>
      </adminObject>
    
      <adminObject jndiName="eis/iSpec_FIND">
        <properties.ExampleRA.InteractionSpec functionName="FIND"/>
      </adminObject>
    
    </server>
  5. 使用資源注入來存取 Servlet 中的資源,例如:
        @Resource(lookup = "eis/conFactory")
        private ConnectionFactory conFactory;
    
        @Resource(lookup = "eis/conSpec")
        private ConnectionSpec conSpec;
    
        @Resource(lookup = "eis/iSpec_ADD")
        private InteractionSpec iSpec_ADD;
    
        @Resource(lookup = "eis/iSpec_FIND")
        private InteractionSpec iSpec_FIND;
    
        ...
    
            MappedRecord input = conFactory.getRecordFactory().createMappedRecord("input");
            input.put("city", "Rochester");
            input.put("state", "Minnesota");
            input.put("population", 106769);
    
            Connection con = conFactory.getConnection(conSpec);
            try {
                Interaction interaction = con.createInteraction();
                interaction.execute(iSpec_ADD, input);
                interaction.close();
            } finally {
                con.close();
            }
    註: 如果您想要從名稱空間查閱資源,而不使用注入,則必須在 server.xml 檔案中啟用 JNDI 特性。

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

資訊中心條款 | 意見


「時間戳記」圖示 前次更新: 2015 年 6 月 22 日
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=phil&product=was-libcore-mp&topic=twlp_jca_config_dep
檔名:twlp_jca_config_dep.html