![](/img/trans.png)
[英]Pivotal GemFire: PDX serializer config in Spring Data GemFire
[英]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
, gfsh
命令无法识别我的Spring bean标签,并且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文档的spring-data-gemfire:2.0.7.RELEASE
更新了从“ gemfire
”到“ geode
”的XML模式路径。
尝试使用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“ /”也正在打印“文件存在”。
更新:
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
,它完全用于gfsh>start server --name=SpringConfiguredServer --spring-xml-location-/path/to/spring/context.xml
,当SDG依赖于Pivotal GemFire,这显然形成了循环依赖。
2)与版本有关时,Pivotal GemFire远远落后于Spring生态系统的当前状态。 即使是最新的版本,9.3.0,船舶与过时的春天 JAR文件,如核心Spring框架 4.3.13.RELEASE
,当核心Spring框架 4.3.17.RELEASE
已经可用以及5.0.6.RELEASE
,与5.1的地平线。
话虽如此,当使用start server
命令--spring-xml-location
选项从Gfsh start server
时,仍然可以使用Spring配置和引导您的Pivotal GemFire服务器。 您仅需要根据正在使用的Pivotal GemFire版本下载适当的SDG版本(例如(9.3.0)),然后在启动服务器时将SDG放在类路径中。
注意:当前, SDG 2.1.0.M3 (SD Lovelace )是基于Pivotal GemFire 9.3和更高版本的唯一版本; 当前设置为9.5.0。
注意:也不是,我不特别记得我是否遇到过任何在从SDG Lovelace从Pivotal GemFire 9.3逐步升级到9.4并最终达到9.5的过程中发生任何更改的API。 如果您在使用
spring-data-gemfire:2.1.0.M3
,也可以使用当时基于 Pivotal GemFire 9.3的spring-data-gemfire:2.1.0.M2
。
因此,按照上面的食谱,您将执行以下操作...
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.