启动时出现 Gemfire PDX 错误:PDX 元数据已创建为对等元数据区域。请先创建您的池

Gemfire PDX error on startup : The PDX metadata has already been created as a peer metadata region. Please create your pools first

我是 gemfire 的新手,使用它启动我的应用程序时遇到问题。

我得到的错误是

[info 2015/05/22 10:55:39.746 BRT  <localhost-startStop-1> tid=0xf] Marking DistributionManager <v0>:17758 as closed.
10:55:40.922 [localhost-startStop-1] ERROR org.springframework.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'gfPool': Invocation of init method failed; nested exception is com.gemstone.gemfire.pdx.PdxInitializationException: The PDX metadata has already been created as a peer metadata region. Please create your pools first
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1566) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getObject(AbstractBeanFactory.java:303) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:743) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757) ~[spring-context-4.1.4.RELEASE.jar:4.1.4.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480) ~[spring-context-4.1.4.RELEASE.jar:4.1.4.RELEASE]
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403) ~[spring-web-4.1.4.RELEASE.jar:4.1.4.RELEASE]
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306) [spring-web-4.1.4.RELEASE.jar:4.1.4.RELEASE]
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106) [spring-web-4.1.4.RELEASE.jar:4.1.4.RELEASE]
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4728) [catalina.jar:8.0.21]
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5166) [catalina.jar:8.0.21]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [catalina.jar:8.0.21]
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409) [catalina.jar:8.0.21]
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1399) [catalina.jar:8.0.21]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_45]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_45]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_45]
    at java.lang.Thread.run(Thread.java:745) [?:1.8.0_45]
Caused by: com.gemstone.gemfire.pdx.PdxInitializationException: The PDX metadata has already been created as a peer metadata region. Please create your pools first
    at com.gemstone.gemfire.pdx.internal.PeerTypeRegistration.creatingPool(PeerTypeRegistration.java:501) ~[gemfire-8.0.0.jar:?]
    at com.gemstone.gemfire.pdx.internal.TypeRegistry.creatingPool(TypeRegistry.java:273) ~[gemfire-8.0.0.jar:?]
    at com.gemstone.gemfire.internal.cache.PoolFactoryImpl.create(PoolFactoryImpl.java:439) ~[gemfire-8.0.0.jar:?]
    at org.springframework.data.gemfire.client.PoolFactoryBean.afterPropertiesSet(PoolFactoryBean.java:172) ~[spring-data-gemfire-1.6.0.RELEASE.jar:1.6.0.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1625) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1562) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]
    ... 21 more

这是我的配置

gemfire-context.xml

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

     <gfe:client-cache id="gemfireClientCache"
        cache-xml-location="classpath:client.xml" pool-name="gfPool" use-bean-factory-locator="false" />

    <gfe:pool id="gfPool" max-connections="10">
        <gfe:locator host= "127.0.0.1" port="9980" />                   
    </gfe:pool>

    <gfe:lookup-region id="myRegion" name="myRegion" cache-ref="gemfireClientCache" />


</beans>  

这里是Client.xml

 <pdx read-serialized="false">
    <pdx-serializer>
        <class-name>com.gemstone.gemfire.pdx.ReflectionBasedAutoSerializer</class-name>
        <parameter name="classes">
            <string>br.com.xxx.*</string>
        </parameter>
        <parameter name="check-portability">
            <string>true</string>
        </parameter>
    </pdx-serializer>
</pdx>
<region name="myRegion">
    <region-attributes refid="PROXY" />
</region>

我的applicationContext.xml

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:gfe="http://www.springframework.org/schema/gemfire"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd


http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd">

    <!-- Use this configuration to test locally -->

    <gfe:cache id="gemfireCache" pdx-persistent="true"/>

    <gfe:partitioned-region id="myRegion" data-policy="PARTITION"/>

    <import resource="classpath:registry-gemfire-context.xml"/>

    <import resource="classpath:br/com/xxx/context.xml"/>

    <context:component-scan base-package="br.com.xxx.*"/>

    <bean id="string" class="java.lang.String"/>

</beans>

您可以尝试在 Spring 中配置 Client.xml 中的内容。

知道了。

问题是 applicationContext.xml 上的区域名称有一个拼写错误(小写字母)所以该区域没有被创建,之后我试图将它添加到池中。

无论如何,那个错误信息太可怕了……也许与它缺失的区域相关的东西会有很大帮助。

希望对其他人有所帮助。

同意,错误消息可能不是那么有用,但这是 GemFire 特定的异常(即 PdxInitializationException)和错误消息。

此外,这里有一些提示...

  1. 如果您不打算更改 SDG 在 XML 命名空间对应于...中定义的常量 https://github.com/spring-projects/spring-data-gemfire/blob/master/src/main/java/org/springframework/data/gemfire/config/GemfireConstants.java#L27-31.

通过这种方式,任何客户端区域都将自动在您的配置中适当地分配 1 个且唯一的池,前提是,如@dturanski 所述,您放弃本机 GemFire XML 配置并定义您的客户端地区如此...

<gfe:client-region id="myRegion" shortcut="PROXY"/>

然后"myRegion"自动关联ClientCache和client Pool

  1. 您也不需要在服务器端 PARTITION 区域上显式设置 DataPolicy...

partitioned-region> 没有 persistent 属性设置为 true (默认为 false)表示分区(即它是多余的)。

  1. 您还可以使用 元素在 ClientCache 上定义 PDX 序列化。有关详细信息,请参阅 XML namespace

  2. 最后,虽然您在服务器端的 Spring 配置中做了正确的事情,在 GemFire 配置之后显式声明 元素,但请确保继续这样做,否则随着用例和需求的增长,你可能会 运行 出现意想不到的行为,特别是如果你将区域注入,比如 DAO(而不是使用 SDG Repository 抽象),例如

事实上,将 GemFire 配置与您的应用程序配置完全分开并依赖导入可能更明智,就像您对

所做的那样

registry-gemfire-context.xml,以及... br/com/xxx/context.xml

GemFire 是一种复杂的动物,因此保持封装、组织和简单是 GemFire 成功的关键。

希望这对您有所帮助;干杯!