[英]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.