![[8.5.5.2 或更高版本]](../ng_v8552.gif)

配置 JCA 连接工厂
您可以配置符合 Java™ EE 连接器体系结构 (JCA) 规范的连接工厂。
关于此任务
注: 要为 Liberty 概要文件配置 JCA 支持,必须使用WebSphere® Application Server Developer Tools for Eclipse 的服务器配置编辑器的“源”视图或某个其他文本编辑器来编辑 server.xml 文件。本主题假定在服务器中已配置具有唯一标识 MyAdapter 的资源适配器,请参阅有关配置资源适配器的文档以获取更多详细信息。以下步骤中提供了配置基本场景的端到端示例。
注: 不支持在 WebSphere® Development Tools (WDT) 的“设计”视图中编辑连接工厂、管理对象、激活规范和资源适配器的服务器配置的属性子元素。
过程
示例
使用以下示例以了解如何配置具有两种连接工厂的资源适配器,这两种连接工厂具有唯一接口类名。
在 ra.xml 文件中的以下片段中,MyAdapter 资源适配器提供了具有唯一接口类名的两种连接工厂:
<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>
使用以下示例以了解如何配置具有两种连接工厂的资源适配器,这两种连接工厂具有唯一实现类名。
在 ra.xml 文件中的以下片段中,MyAdapter 资源适配器提供了具有唯一实现类名的两种连接工厂:
<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>
使用以下示例以了解如何配置具有两种连接工厂的资源适配器,这两种连接工厂的简单接口类名或实现类名均不唯一。
在 ra.xml 文件的以下片段中,MyAdapter 资源适配器提供了两种连接工厂,且这两种连接工厂的简单接口类名或实现类名均不唯一:
<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 配置元素的信息以了解如何覆盖配置元素名称的后缀。