【发布时间】:2020-03-31 17:24:09
【问题描述】:
我正在尝试通过以下链接在 IBM WebSphere Liberty 基础上为 Gemfire 9.8 设置 JCA 资源适配器 https://gemfire.docs.pivotal.io/98/geode/reference/archive_transactions/JTA_transactions.html#concept_cp1_zx1_wk
这是我的 ra.xml:
<connector xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/connector_1_5.xsd"
version="1.5">
<display-name>GFE JCA Adaptor</display-name>
<vendor-name></vendor-name>
<spec-version>1.5</spec-version>
<eis-type>GFE JCA</eis-type>
<version>1.5</version>
<resourceadapter>
<config-property>
<config-property-name>ProductName</config-property-name>
<config-property-type>java.lang.String</config-property-type>
<config-property-value>GemFire</config-property-value>
</config-property>
<config-property>
<config-property-name>UserName</config-property-name>
<config-property-type>java.lang.String</config-property-type>
<config-property-value/>
</config-property>
<config-property>
<config-property-name>Version</config-property-name>
<config-property-type>java.lang.String</config-property-type>
<config-property-value>8.0</config-property-value>
</config-property>
<outbound-resourceadapter>
<connection-definition>
<managedconnectionfactory-class>org.apache.geode.internal.ra.spi.JCAManagedConnectionFactory</managedconnectionfactory-class>
<connectionfactory-interface>org.apache.geode.ra.GFConnectionFactory</connectionfactory-interface>
<connectionfactory-impl-class>org.apache.geode.internal.ra.GFConnectionFactoryImpl</connectionfactory-impl-class>
<connection-interface>org.apache.geode.ra.GFConnection</connection-interface>
<connection-impl-class>org.apache.geode.internal.ra.GFConnectionImpl</connection-impl-class>
<transaction-support>LocalTransaction</transaction-support>
<reauthentication-support>false</reauthentication-support>
</connection-definition>
</outbound-resourceadapter>
</resourceadapter>
这是我的资源适配器设置:
<library id="gemfireRaLib" apiTypeVisibility="spec, ibm-api, stable, third-party, api">
<fileset dir="path/to/geode-lib" includes="geode-dependencies.jar"/>
</library>
<resourceAdapter id="gemfireJCA" location="/path/to/geode-lib/geode-jca-9.8.3.rar">
<classloader apiTypeVisibility="spec, ibm-api, stable, third-party, api" commonLibraryRef="gemfireRaLib" delegation="parentFirst"/>
</resourceAdapter>
当我启动我的 liberty 服务器时,spring boot 初始化失败,提示找不到 ClassNotFoundException org.apache.geode.ra.GFConnectionFactory。
然后我把所有 geode 依赖作为一个共享库:
<library id="gemfireRaLib" apiTypeVisibility="spec, ibm-api, stable, third-party, api">
<fileset dir="/path/to/geode-lib" includes="geode-dependencies.jar"/>
<fileset dir="/path/to/geode-lib" includes="*.jar"/>
</library>
<resourceAdapter id="gemfireJCA" location="/path/to/geode-jca-9.8.3.rar">
<classloader apiTypeVisibility="spec, ibm-api, stable, third-party, api" commonLibraryRef="gemfireRaLib" delegation="parentFirst"/>
</resourceAdapter>
和
<webApplication contextRoot="apprRoot13" location="/path/to/mylocation.war" name="App13" id="App13">
<classloader apiTypeVisibility="spec, ibm-api, stable, third-party, api" commonProviderRef="gemfireRaLib" delegation="parentFirst" />
</webApplication>
错误:
spring-data-gemfire initialization fails:
AnnotationConfigServletWebServerApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [applicationContext-gemfire.xml]; nested exception is java.lang.NoClassDefFoundError: org.apache.geode.cache.PartitionResolver
在上述所有场景中,我都成功安装了 gemfireJCA 适配器。
更新 1
/path/to/shared/geode-lib/ 包含以下 jars:
geode-common-9.8.3.jar
geode-cq-9.8.3.jar
geode-jca-9.8.3.rar
geode-management-9.8.3.jar
geode-core-9.8.3.jar
geode-dependencies.jar
geode-lucene-9.8.3.jar
geode-wan-9.8.3.jar
当我将它们打包到 WAR 中时,应用程序启动但失败了
lookup = (GFConnectionFactory) template.lookup("gfe/jca");
说:
java.lang.ClassCastException: org.apache.geode.internal.ra.GFConnectionFactoryImpl incompatible with org.apache.geode.ra.GFConnectionFactory
我得到 java.lang.ClassCastException: org.apache.geode.internal.ra.GFConnectionFactoryImpl incompatible with org.apache.geode.ra.GFConnectionFactory 因为 GFConnectionFactoryImpl 和 GFConnectionFactory 是由不同的类加载器加载的。这就是我创建 geode-lib 共享库的原因。在 JCA 资源适配器和 Web 应用程序之间共享它
【问题讨论】:
-
这个我没试过,但是假设你想在你的应用程序中使用RA中的类,你需要设置webApplication/classloader classProviderRef属性来引用资源适配器。所以这个:
-
谢谢,但是当我这样做时,我收到以下错误 java.lang.ClassCastException: org.apache.geode.internal.ra.GFConnectionFactoryImpl incompatible with org.apache.geode.ra.GFConnectionFactory It是来自 JCA 类加载器的 GFConnectionFactoryImpl 无法转换为 Web 应用程序的 GFConnectionFactory。类加载器委托是 parentFirst。
标签: spring-boot websphere-liberty gemfire spring-data-gemfire