ClassLoader问题:IBM WebSphere LibertyBase中的GemFire JCA资源适配器

问题描述 投票:0回答:1

我正在通过以下链接尝试在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>

启动自由服务器时,春季启动初始化失败,提示未找到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初始化失败:AnnotationConfigServletWebServerApplicationContext-上下文初始化期间遇到的异常-取消刷新尝试:org.springframework.beans.factory.BeanDefinitionStoreException:从类路径资源[applicationContext-gemfire.xml]解析XML文档的意外异常;嵌套的异常是java.lang.NoClassDefFoundError:org.apache.geode.cache.PartitionResolver

在以上所有情况下,我都成功安装了gemfireJCA适配器。

我确实在这个问题上停留了几个小时。非常感谢您提供有关如何在Liberty上正确设置Gemfire JCA资源适配器的任何帮助或建议。

更新1:/ path / to / shared / geode-lib /包含以下jar:

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与org.apache.geode.ra.GFConnectionFactory不兼容,因为GFConnectionFactoryImpl和GFConnectionFactory由不同的类加载器加载。这就是为什么我创建了geode-lib共享库。在JCA资源适配器和Web应用程序之间共享它]

我正在尝试通过链接https://gemfire.docs.pivotal.io/98/geode/reference/archive_transactions / ...链接在IBM WebSphere Liberty上为Gemfire 9.8设置JCA资源适配器。]] >

是什么导致NoClassDefFoundError

nested exception is java.lang.NoClassDefFoundError: org.apache.geode.cache.PartitionResolver

好像您的基于Spring(Data GemFire)的Web应用程序在部署的工件(WAR ??)中没有所有必需的依赖项?

关于org.apache.geode.ra.GFConnectionFactory,该类在io.pivotal.gemfire:geode-core:9.8.7中。

在WAS Liberty描述符定义中:

<library id="gemfireRaLib" apiTypeVisibility="spec, ibm-api, stable, third-party, api">
  <fileset dir="/applis/11472-tpa00-tpa/wlb/shared/geode-lib" includes="geode-dependencies.jar"/>
  <fileset dir="/applis/11472-tpa00-tpa/wlb/shared/geode-lib" includes="*.jar"/>
</library> 

我认为这是不正确的:

<fileset dir="/applis/11472-tpa00-tpa/wlb/shared/geode-lib" includes="geode-dependencies.jar"/>

通过示例,Pivotal GemFire 9.8基于Apache Geode 1.9。因此,我将使用Apache Geode 1.9发行版进行演示。

$ cd apache-geode-1.9.2/
jblum-mbpro-2:apache-geode-1.9.2 jblum$ $ jar -tvf lib/geode-dependencies.jar 
     0 Tue Oct 15 06:08:24 PDT 2019 META-INF/
  2250 Tue Oct 15 06:08:24 PDT 2019 META-INF/MANIFEST.MF
 19957 Tue Oct 15 06:05:14 PDT 2019 META-INF/LICENSE
   575 Tue Oct 15 06:05:14 PDT 2019 META-INF/NOTICE

您是否知道geode-dependencies.jar是仅用于清单的JAR文件?

仅清单文件的JAR是引用应用程序类路径中所需的其他JAR的一种便捷方法,因此您无需独立列出所有必需的JAR,例如...

$ java -classpath /path/to/A.jar;/path/to/B.jar;...;/path/to/N.jar

仅清单文件的JAR不包含清单文件以外的任何类文件或其他资源,如上所示。

仅用于清单的JAR包含META-INF/MANIFEST.MF,并且其Class-Path属性设置为所需的JAR。 “所需的JAR”是相对于仅清单的JAR(例如geode-dependecies.jar)。

由于geode-dependencies.jar包含在~/apache-geode-1.9.2/lib中,因此只有~/apache-geode-1.9.2/lib目录中的JAR是可解析的:

$ ll lib/
total 133376
-rw-r--r--@ 1 jblum  staff    114165 Jun 13  2019 HdrHistogram-2.1.9.jar
-rw-r--r--@ 1 jblum  staff    143577 Jul 17  2019 HikariCP-3.2.0.jar
-rw-r--r--@ 1 jblum  staff     29779 Jun 13  2019 LatencyUtils-2.0.3.jar
-rw-r--r--@ 1 jblum  staff    445288 Feb  6  2019 antlr-2.7.7.jar
-rw-r--r--@ 1 jblum  staff    346684 Feb  6  2019 classgraph-4.0.6.jar
-rw-r--r--@ 1 jblum  staff    246174 Feb  6  2019 commons-beanutils-1.9.3.jar
-rw-r--r--@ 1 jblum  staff    284184 Feb  6  2019 commons-codec-1.10.jar
-rw-r--r--@ 1 jblum  staff    588337 Feb  6  2019 commons-collections-3.2.2.jar
-rw-r--r--@ 1 jblum  staff    196768 Feb  6  2019 commons-digester-2.1.jar
-rw-r--r--@ 1 jblum  staff    214788 Feb  6  2019 commons-io-2.6.jar
-rw-r--r--@ 1 jblum  staff    501879 Feb  6  2019 commons-lang3-3.8.1.jar
-rw-r--r--@ 1 jblum  staff     61829 Feb  6  2019 commons-logging-1.2.jar
-rw-r--r--@ 1 jblum  staff   1692782 Aug 21  2019 commons-math3-3.2.jar
-rw-r--r--@ 1 jblum  staff    112005 Aug 21  2019 commons-modeler-2.0.1.jar
-rw-r--r--@ 1 jblum  staff    186077 Feb  6  2019 commons-validator-1.6.jar
-rw-r--r--@ 1 jblum  staff  18800316 Jun 13  2019 fastutil-8.2.2.jar
-rw-r--r--@ 1 jblum  staff     15322 Feb  6  2019 findbugs-annotations-1.3.9-1.jar
-rw-r--r--@ 1 jblum  staff     23712 Aug 21  2019 geo-0.7.1.jar
-rw-r--r--@ 1 jblum  staff     12987 Oct 15 06:07 geode-common-1.9.2.jar
-rw-r--r--@ 1 jblum  staff    130813 Oct 15 06:08 geode-connectors-1.9.2.jar
-rw-r--r--@ 1 jblum  staff  12280133 Oct 15 06:08 geode-core-1.9.2.jar
-rw-r--r--@ 1 jblum  staff     96220 Oct 15 06:08 geode-cq-1.9.2.jar
-rw-r--r--@ 1 jblum  staff      8200 Oct 15 06:08 geode-dependencies.jar
-rw-r--r--@ 1 jblum  staff     24431 Oct 15 06:08 geode-jca-1.9.2.rar
-rw-r--r--@ 1 jblum  staff    220612 Oct 15 06:08 geode-lucene-1.9.2.jar
-rw-r--r--@ 1 jblum  staff    103539 Oct 15 06:07 geode-management-1.9.2.jar
-rw-r--r--@ 1 jblum  staff     14225 Oct 15 06:08 geode-old-client-support-1.9.2.jar
-rw-r--r--@ 1 jblum  staff    110608 Oct 15 06:08 geode-protobuf-1.9.2.jar
-rw-r--r--@ 1 jblum  staff    607104 Oct 15 06:07 geode-protobuf-messages-1.9.2.jar
-rw-r--r--@ 1 jblum  staff     22805 Oct 15 06:08 geode-rebalancer-1.9.2.jar
-rw-r--r--@ 1 jblum  staff    516805 Oct 15 06:08 geode-redis-1.9.2.jar
-rw-r--r--@ 1 jblum  staff     87754 Oct 15 06:08 geode-wan-1.9.2.jar
-rw-r--r--@ 1 jblum  staff     41262 Oct 15 06:08 geode-web-1.9.2.jar
-rw-r--r--@ 1 jblum  staff      8236 Oct 15 06:08 gfsh-dependencies.jar
-rw-r--r--@ 1 jblum  staff      9902 Aug 21  2019 grumpy-core-0.2.2.jar
-rw-r--r--@ 1 jblum  staff    767140 Jun 13  2019 httpclient-4.5.6.jar
-rw-r--r--@ 1 jblum  staff    326356 Jun 13  2019 httpcore-4.4.10.jar
-rw-r--r--@ 1 jblum  staff     20024 Jun 13  2019 istack-commons-runtime-2.2.jar
-rw-r--r--@ 1 jblum  staff     66894 May 13  2019 jackson-annotations-2.9.8.jar
-rw-r--r--@ 1 jblum  staff    325619 Feb  6  2019 jackson-core-2.9.8.jar
-rw-r--r--@ 1 jblum  staff   1347236 Feb  6  2019 jackson-databind-2.9.8.jar
-rw-r--r--@ 1 jblum  staff    283858 Aug 21  2019 jansi-1.17.1.jar
-rw-r--r--@ 1 jblum  staff     78030 Jun 13  2019 javax.activation-1.2.0.jar
-rw-r--r--@ 1 jblum  staff     56674 Jun 13  2019 javax.activation-api-1.2.0.jar
-rw-r--r--@ 1 jblum  staff    219146 Aug 21  2019 javax.mail-api-1.6.2.jar
-rw-r--r--@ 1 jblum  staff     69900 Jun 13  2019 javax.resource-api-1.7.1.jar
-rw-r--r--@ 1 jblum  staff     95806 May 13  2019 javax.servlet-api-3.1.0.jar
-rw-r--r--@ 1 jblum  staff     28016 Jun  7  2019 javax.transaction-api-1.3.jar
-rw-r--r--@ 1 jblum  staff    128076 Jun 13  2019 jaxb-api-2.3.1.jar
-rw-r--r--@ 1 jblum  staff   1099204 Jun 13  2019 jaxb-impl-2.3.1.jar
-rw-r--r--@ 1 jblum  staff    195664 Jul 16  2019 jetty-http-9.4.12.v20180830.jar
-rw-r--r--@ 1 jblum  staff    139436 Jun 13  2019 jetty-io-9.4.12.v20180830.jar
-rw-r--r--@ 1 jblum  staff     93077 Jul 16  2019 jetty-security-9.4.12.v20180830.jar
-rw-r--r--@ 1 jblum  staff    609290 Jun 13  2019 jetty-server-9.4.12.v20180830.jar
-rw-r--r--@ 1 jblum  staff    110983 Oct  7 15:01 jetty-servlet-9.4.12.v20180830.jar
-rw-r--r--@ 1 jblum  staff    502985 Jun 13  2019 jetty-util-9.4.12.v20180830.jar
-rw-r--r--@ 1 jblum  staff    128579 Jul 16  2019 jetty-webapp-9.4.12.v20180830.jar
-rw-r--r--@ 1 jblum  staff     52044 Jul 16  2019 jetty-xml-9.4.12.v20180830.jar
-rw-r--r--@ 1 jblum  staff   2512913 Feb  6  2019 jgroups-3.6.14.Final.jar
-rw-r--r--@ 1 jblum  staff    213854 Feb  6  2019 jline-2.12.jar
-rw-r--r--@ 1 jblum  staff    914597 Feb  6  2019 jna-4.1.0.jar
-rw-r--r--@ 1 jblum  staff     78146 Feb  6  2019 jopt-simple-5.0.4.jar
-rw-r--r--@ 1 jblum  staff    264060 Jul  3  2019 log4j-api-2.11.1.jar
-rw-r--r--@ 1 jblum  staff   1607947 Aug  8  2019 log4j-core-2.11.1.jar
-rw-r--r--@ 1 jblum  staff     12664 Aug 21  2019 log4j-jcl-2.11.1.jar
-rw-r--r--@ 1 jblum  staff     23999 Sep  3  2019 log4j-jul-2.11.1.jar
-rw-r--r--@ 1 jblum  staff     23241 Aug 20  2019 log4j-slf4j-impl-2.11.1.jar
-rw-r--r--@ 1 jblum  staff   1513791 Feb  6  2019 lucene-analyzers-common-6.6.2.jar
-rw-r--r--@ 1 jblum  staff     26142 Feb  6  2019 lucene-analyzers-phonetic-6.6.2.jar
-rw-r--r--@ 1 jblum  staff   2783525 Feb  6  2019 lucene-core-6.6.2.jar
-rw-r--r--@ 1 jblum  staff    237891 Feb  6  2019 lucene-queries-6.6.2.jar
-rw-r--r--@ 1 jblum  staff    405545 Feb  6  2019 lucene-queryparser-6.6.2.jar
-rw-r--r--@ 1 jblum  staff    422554 Jun 13  2019 micrometer-core-1.1.3.jar
-rw-r--r--@ 1 jblum  staff    409467 Feb  6  2019 mx4j-3.0.2.jar
-rw-r--r--@ 1 jblum  staff    172221 Aug 21  2019 mx4j-remote-3.0.2.jar
-rw-r--r--@ 1 jblum  staff    497017 Aug 21  2019 mx4j-tools-3.0.1.jar
-rw-r--r--@ 1 jblum  staff   3905888 Aug 21  2019 netty-all-4.1.31.Final.jar
-rw-r--r--@ 1 jblum  staff   1421323 Aug 21  2019 protobuf-java-3.6.1.jar
-rw-r--r--@ 1 jblum  staff     17522 Oct 15 06:08 ra.jar
-rw-r--r--@ 1 jblum  staff    110848 Feb  6  2019 rmiio-2.1.2.jar
-rw-r--r--@ 1 jblum  staff     13601 Feb  6  2019 shiro-cache-1.4.0.jar
-rw-r--r--@ 1 jblum  staff     18037 Feb  6  2019 shiro-config-core-1.4.0.jar
-rw-r--r--@ 1 jblum  staff     43303 Feb  6  2019 shiro-config-ogdl-1.4.0.jar
-rw-r--r--@ 1 jblum  staff    410541 Feb  6  2019 shiro-core-1.4.0.jar
-rw-r--r--@ 1 jblum  staff     24024 Feb  6  2019 shiro-crypto-cipher-1.4.0.jar
-rw-r--r--@ 1 jblum  staff     10873 Feb  6  2019 shiro-crypto-core-1.4.0.jar
-rw-r--r--@ 1 jblum  staff     34298 Feb  6  2019 shiro-crypto-hash-1.4.0.jar
-rw-r--r--@ 1 jblum  staff     19210 Feb  6  2019 shiro-event-1.4.0.jar
-rw-r--r--@ 1 jblum  staff     51122 Feb  6  2019 shiro-lang-1.4.0.jar
-rw-r--r--@ 1 jblum  staff     41203 Feb  6  2019 slf4j-api-1.7.25.jar
-rw-r--r--@ 1 jblum  staff     57954 Feb  6  2019 snappy-0.4.jar
-rw-r--r--@ 1 jblum  staff    379904 Sep  4  2019 spring-aop-4.3.20.RELEASE.jar
-rw-r--r--@ 1 jblum  staff    763445 Aug 21  2019 spring-beans-4.3.20.RELEASE.jar
-rw-r--r--@ 1 jblum  staff   1142763 Aug 21  2019 spring-context-4.3.20.RELEASE.jar
-rw-r--r--@ 1 jblum  staff   1130638 Aug 21  2019 spring-core-4.3.20.RELEASE.jar
-rw-r--r--@ 1 jblum  staff    274952 Aug 21  2019 spring-expression-4.3.20.RELEASE.jar
-rw-r--r--@ 1 jblum  staff    195025 Feb  6  2019 spring-shell-1.2.0.RELEASE.jar
-rw-r--r--@ 1 jblum  staff    828588 Sep  4  2019 spring-web-4.3.20.RELEASE.jar

查看geode-dependenies.jar目录中的lib吗?

现在,让我们检查META-INF/MANIFEST.MF文件。

$ $ jar -xvf lib/geode-dependencies.jar META-INF/MANIFEST.MF
 inflated: META-INF/MANIFEST.MF

$ cat META-INF/MANIFEST.MF 
Manifest-Version: 1.0
Organization: Apache Software Foundation (ASF)
Class-Path: geode-common-1.9.2.jar geode-core-1.9.2.jar geode-connecto
 rs-1.9.2.jar geode-lucene-1.9.2.jar geode-redis-1.9.2.jar geode-old-c
 lient-support-1.9.2.jar geode-protobuf-1.9.2.jar geode-protobuf-messa
 ges-1.9.2.jar geode-management-1.9.2.jar geode-wan-1.9.2.jar geode-cq
 -1.9.2.jar geode-rebalancer-1.9.2.jar antlr-2.7.7.jar jgroups-3.6.14.
 Final.jar jackson-databind-2.9.8.jar jackson-annotations-2.9.8.jar sp
 ring-shell-1.2.0.RELEASE.jar commons-io-2.6.jar commons-validator-1.6
 .jar javax.activation-1.2.0.jar jaxb-api-2.3.1.jar jaxb-impl-2.3.1.ja
 r istack-commons-runtime-2.2.jar commons-lang3-3.8.1.jar micrometer-c
 ore-1.1.3.jar fastutil-8.2.2.jar javax.resource-api-1.7.1.jar jna-4.1
 .0.jar jopt-simple-5.0.4.jar log4j-slf4j-impl-2.11.1.jar log4j-core-2
 .11.1.jar log4j-jcl-2.11.1.jar log4j-jul-2.11.1.jar log4j-api-2.11.1.
 jar jetty-webapp-9.4.12.v20180830.jar jetty-servlet-9.4.12.v20180830.
 jar jetty-security-9.4.12.v20180830.jar jetty-server-9.4.12.v20180830
 .jar spring-core-4.3.20.RELEASE.jar snappy-0.4.jar shiro-core-1.4.0.j
 ar classgraph-4.0.6.jar rmiio-2.1.2.jar jansi-1.17.1.jar shiro-cache-
 1.4.0.jar shiro-crypto-hash-1.4.0.jar shiro-crypto-cipher-1.4.0.jar s
 hiro-config-ogdl-1.4.0.jar shiro-config-core-1.4.0.jar shiro-event-1.
 4.0.jar shiro-crypto-core-1.4.0.jar shiro-lang-1.4.0.jar slf4j-api-1.
 7.25.jar commons-beanutils-1.9.3.jar commons-collections-3.2.2.jar ht
 tpclient-4.5.6.jar commons-logging-1.2.jar javax.servlet-api-3.1.0.ja
 r httpcore-4.4.10.jar jackson-core-2.9.8.jar javax.activation-api-1.2
 .0.jar HdrHistogram-2.1.9.jar LatencyUtils-2.0.3.jar javax.transactio
 n-api-1.3.jar jetty-xml-9.4.12.v20180830.jar jetty-http-9.4.12.v20180
 830.jar jetty-io-9.4.12.v20180830.jar jline-2.12.jar jetty-util-9.4.1
 2.v20180830.jar commons-codec-1.10.jar HikariCP-3.2.0.jar lucene-anal
 yzers-phonetic-6.6.2.jar lucene-analyzers-common-6.6.2.jar lucene-que
 ryparser-6.6.2.jar lucene-core-6.6.2.jar lucene-queries-6.6.2.jar geo
 -0.7.1.jar netty-all-4.1.31.Final.jar grumpy-core-0.2.2.jar commons-m
 ath3-3.2.jar protobuf-java-3.6.1.jar
Title: geode
Version: 1.9.2
Created-By: jdeppe

[Manifiedt Class-Path文件属性中列出的所有JAR都是相对于geode-dependencies.jar的,也是您在WAS内类路径上所需的JAR ...因此,Geode / GemFire JAR至少需要多个<fileset>声明...

geode-coregeode-cq大地偏见大地湾

...以及Spring Data GemFire needs的任何JAR,包括可能基于GemFire使用(也许)的功能(例如)的第三方库(即传递依赖项),例如Lucene ..

lucene-xyz.jar

有道理吗?

让我们从这里开始,并在需要时进行迭代。这应该会使您更进一步。

希望这会有所帮助!

spring-boot websphere-liberty gemfire spring-data-gemfire
1个回答
0
投票

是什么导致NoClassDefFoundError

nested exception is java.lang.NoClassDefFoundError: org.apache.geode.cache.PartitionResolver
© www.soinside.com 2019 - 2024. All rights reserved.