0

我对 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$1.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>
4

3 回答 3

1

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

于 2015-05-22T15:30:16.600 回答
1

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

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

  1. 如果您不打算更改默认值,则无需显式地给 <gfe:cache> 或 <gfe:client-cache> 和 <gfe:pool> 一个 ID,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 Region 上显式设置 DataPolicy ...

由于 <gfe: partitioned-region > 没有将持久属性设置为true(默认为false)意味着 PARTITION (即它是多余的)。

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

  2. 最后,虽然您在服务器端的 Spring 配置中做了正确的事情,在 GemFire 配置之后显式声明 <context:component-scan> 元素,但请务必继续执行此操作,否则您可能会遇到意外行为随着您的用例和需求的增长,特别是如果您将区域注入到 DAO 中(而不是使用SDG 存储库抽象)。

事实上,将 GemFire 配置从您的应用程序配置中完全分离出来并像您所做的那样依赖导入可能更明智

registry-gemfire-context.xml 和... br/com/xxx/context.xml

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

希望这可以帮助; 干杯!

于 2015-05-22T19:59:07.237 回答
0

知道了。

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

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

希望它可以帮助别人。

于 2015-05-22T15:34:42.257 回答