Pivotal GemFire 9.3.0:GemFire 集群中的 Spring Data GemFire XML 配置

Pivotal GemFire 9.3.0: Spring Data GemFire XML config in GemFire cluster

我正在将我的 GemFire 集群从 8.2.7(使用 Spring Data GemFire 1.6.0.RELEASE)迁移到 Pivotal GemFire 9.3.0(SDG 2.0.7.RELEASE)。我正在使用 spring-context.xml(在 cache.xml 中的 initializer 标记下声明)在每个节点上启动缓存服务器时初始化区域。

当我尝试为 Pivotal GemFire 9.3.0 重用相同的 spring-context.xml 时,我的 Spring beans 标签未被 gfsh 命令识别,我收到以下异常:

Caused by: org.xml.sax.SAXParseException; lineNumber: 9; columnNumber: 107; cvc-elt.1: Cannot find the declaration of element 'beans'.

        at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:203)

        at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:134)

spring-context.xml :

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:gfe="http://www.springframework.org/schema/geode"
       xmlns:util="http://www.springframework.org/schema/util"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
                http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/geode http://www.springframework.org/schema/gemfire/spring-geode.xsd
                http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">

    <util:properties id="gemfireProperties">
        <prop key="log-level">config</prop>
        <prop key="locators">hostA[10334],hostB[10334]</prop>
    </util:properties>

    <bean id="mappingPdxSerializer" class="org.springframework.data.gemfire.mapping.MappingPdxSerializer"/>

    <gfe:cache properties-ref="gemfireProperties" pdx-serializer-ref="mappingPdxSerializer"/>

    <gfe:replicated-region id="Product">
    </gfe:replicated-region>

    <gfe:replicated-region id="ProductCustomer">
    </gfe:replicated-region>

</beans>

我根据 spring-data-gemfire:2.0.7.RELEASE 的 Spring 文档将 XML 架构路径从“gemfire”更新为“geode”。

尝试使用 GF 9.1.1 和 SDGF 2.0.7。 (SDGF jar放在lib中)

脚本:

#!/bin/sh
export PATH=$PATH:/var/tmp/user/gemfire/9.1.1:/opt/jdk/1.8.0_71l64/bin/:/var/tmp/user/gemfire/9.1.1/bin/
export GEMFIRE=/var/tmp/user/gemfire/9.1.1/


for i in `ls  /var/tmp/user/gemfire/9.1.1/lib/*.jar`
do
  CLASSPATH=${CLASSPATH}:${i}
done
CLASSPATH=$CLASSPATH:/var/tmp/user/gemfire/9.1.1/config
#echo $CLASSPATH

if [ -e "/var/tmp/user/gemfire/9.1.1/config/spring-context.xml" ]; then
   echo "File exists"
else
 echo "File does not exist"
fi


gfsh start server --name=server1 --server-port=40405 --classpath=$CLASSPATH --spring-xml-location=/var/tmp/user/gemfire/9.1.1/config/spring-context.xml  --locators=hostA[10334],hostB[10334] --mcast-port=0

更新:

FileNotFoundException 抛出:

Caused by: java.io.FileNotFoundException: class path resource [var/tmp/sn17180/gemfire/9.1.1/config/spring-context.xml] cannot be opened because it does not exist

        at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:172)

        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:330)

        ... 17 more

我已经授予所有文件的权限,并且我的脚本中的 -e "/" 也在打印 "File exists"。

更新:

cache.xml

<?xml version="1.0" encoding="UTF-8"?>
<cache xmlns="http://geode.apache.org/schema/cache"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://geode.apache.org/schema/cache http://geode.apache.org/schema/cache/cache-1.0.xsd"
       version="1.0">

  <region name="Parent" refid="REPLICATE">
    <region name="Child" refid="REPLICATE"/>
  </region>

</cache>

gemfire-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:gfe="http://www.springframework.org/schema/gemfire"
       xmlns:util="http://www.springframework.org/schema/util"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
                http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd
                http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">

    <util:properties id="gemfireProperties">
        <prop key="locators">xyz[10334],xyx[10334]</prop>
        <prop key="mcast-port">0</prop>
    </util:properties>

    <bean id="autoSerializer" class="org.apache.geode.pdx.ReflectionBasedAutoSerializer"/>

    <gfe:cache properties-ref="gemfireProperties" cache-xml-location="cache.xml" pdx-serializer-ref="autoSerializer" pdx-read-serialized="true"/>   

</beans>

从 9.x 发布系列开始,Pivotal GemFire 停止与 $GEMFIRE_HOME/lib 目录中的 Spring Data GemFire 一起发货。这有两个主要原因。

1)首先,Pivotal GemFire依赖SDG,这完全是为了gfsh>start server --name=SpringConfiguredServer --spring-xml-location-/path/to/spring/context.xml,这有点令人费解,而SDG依赖Pivotal GemFire,显然形成了循环依赖。

2) Pivotal GemFire 在版本方面明显落后于 Spring 生态系统的当前状态。即使是最新版本 9.3.0,也附带了过时的 Spring JAR,例如core Spring Framework 4.3.13.RELEASE,当 core Spring Framework 4.3.17.RELEASE 已经可用时以及 5.0.6.RELEASE,5.1 即将到来。

话虽如此,当从 Gfsh 启动时,仍然可以使用 Spring 配置和 bootstrap 你的 Pivotal GemFire 服务器 使用 start server 命令,--spring-xml-location 选项。您只需要根据您使用的 Pivotal GemFire 版本(例如 (9.3.0))下载 SDG appropriate version,并在启动服务器时将 SDG 放在类路径中。

NOTE: currently, SDG 2.1.0.M3 (SD Lovelace) is the only version based on Pivotal GemFire 9.3 and later; currently set to 9.5.0.

NOTE: also not, I don't specifically recall whether I ran into any API breaking changes between upgrading SDG Lovelace progressively from Pivotal GemFire 9.3, then to 9.4 and finally arriving at 9.5. If you have trouble with spring-data-gemfire:2.1.0.M3, you can also use spring-data-gemfire:2.1.0.M2 which was based on Pivotal GemFire 9.3 at the time.

因此,按照上面的方法,您将执行以下操作...

gfsh> start server --name=SpringConfiguredServer --classpath=/file/system/path/to/spring-data-gemfire22.1.0.M3.jar --spring-xml-location=/classpath/to/your/spring-context.xml

这应该行得通!

此外,您不需要将架构从 "gemfire" 切换到 "geode"。当您使用 Spring Data GemFire 时,请使用 "spring-gemfire" 模式。当您使用 Spring Data Geode 时,请使用 "spring-geode" 模式。两者都可能有效,但是...

希望对您有所帮助!

-j