配置及部署基本 JCA 資源配接器
您可以配置及部署基本 Java™ EE 連接器架構 (JCA) Connection Factory 和資源配接器。
關於這項作業
程序
- 在 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>
- 將資源配接器保存檔 (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] 中。部署描述子會識別 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>
- 在 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)」特性提供配置元素,以定義 Connection Factory、受管理物件和啟動規格的實例,並讓這些實例與已安裝的資源配接器產生關聯。每一個 JCA 配置元素由兩個基本組件組成:最上層元素和子元素,所配置的實例必須同時具備這兩個元素。
上層主題: 手動管理 Liberty


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