配置和部署基本 JCA 资源适配器
您可配置和部署基本 Java™ EE 连接器体系结构 (JCA) 连接工厂和资源适配器。
关于此任务
过程
- 在 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>
- 将资源适配器 RAR 文件 (ExampleRA.rar) 放到服务器的 dropins 文件夹。 如果您的服务器正在运行,那么您将在控制台日志中看到指示该资源适配器已安装的以下消息:
[AUDIT ] J2CA7001I: Resource adapter ExampleRA installed in 1.306 seconds.
- 检查部署描述符、注释以及资源适配器的其他文档,以确定适配器提供的资源类型以及每个适配器接受的配置属性。 示例资源适配器 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>
- 在 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>
- 使用资源注入以在 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 功能部件。
子主题
- JCA 配置元素概述
Java Platform, Enteprise Edition 连接器体系结构 (JCA) 功能部件提供了配置元素来定义连接工厂、受管对象和激活规范的实例,并使这些实例与已安装的资源适配器相关联。每个 JCA 配置元素都由两个基本部分(顶级元素和子元素)组成,这两部分是所配置的实例必需的。
父主题: 手动管理 Liberty


http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-libcore-mp&topic=twlp_jca_config_dep
文件名:twlp_jca_config_dep.html