配置和部署基本 JCA 资源适配器

您可配置和部署基本 Java™ EE 连接器体系结构 (JCA) 连接工厂和资源适配器。

关于此任务

您可安装资源适配器和配置其提供的资源的实例。本任务使用名为 ExampleRA.rar 的示例资源适配器,它提供了三种类型的资源:一个连接工厂和两种类型的受管对象。

过程

  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. 将资源适配器 RAR 文件 (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.]。部署描述符确定可配置的三种类型的资源。
    <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 功能部件。

用于指示主题类型的图标 任务主题



时间戳记图标 最近一次更新时间: Tuesday, 6 December 2016
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-nd-mp&topic=twlp_jca_config_dep
文件名:twlp_jca_config_dep.html