【问题标题】:Spring Data Gemfire configuration does not connect to locator?Spring Data Gemfire 配置未连接到定位器?
【发布时间】:2013-03-13 16:35:15
【问题描述】:

假设我的目标部署环境中已经运行了 Gemfire 定位器和缓存服务器进程。目标部署环境使用client-server topology

我有一个 Spring 3.1 MVC 应用程序,它想要使用 Gemfire 缓存。我正在使用 Spring Data Gemfire 1.2.2 和 Gemfire 6.6.1

所以我将以下内容添加到我的spring.xml

<util:properties id="gemfire-props">
    <prop key="log-level">${gemfire.log-level}</prop>
    <prop key="mcast-port">${gemfire.mcast-port}</prop>
    <prop key="locators">${gemfire.locators}</prop>
</util:properties>

<gfe:cache id="gemfireCache" properties-ref="gemfire-props"/>
<gfe:replicated-region id="myCacheRegion" cache-ref="gemfireCache">
    <gfe:cache-listener>
        <ref bean="gemfireCacheLogListener"/>
    </gfe:cache-listener>
    <gfe:entry-ttl timeout="${gemfire.myCacheRegion.ttl}" action="DESTROY"/>
</gfe:replicated-region>

<bean id="gemfireCacheLogListener" class="org.awong.GemfireCacheLogListener"></bean>

<bean id="cacheManager" class="org.springframework.data.gemfire.support.GemfireCacheManager"
    p:cache-ref="gemfireCache">
    <property name="regions">
        <set>
            <ref bean="myCacheRegion"/>
        </set>
    </property>
</bean>

假设外部 JAR 依赖项都已在 Maven 中正确定义。还假设我加载了一个属性文件,该文件定义了上面引用的属性值。 locators 属性定义为使用已启动的 Gemfire 定位器的 IP 和端口。

我相信这应该足够好,以便我可以在我的 MVC 应用程序中使用 @Cacheable 注释 bean。我希望这些配置在应用服务器中启动一个定位器以连接到 Gemfire 网格,将 myCacheRegion 添加到 Gemfire 缓存服务器,然后 cacheManager 应该能够使用新的缓存区域。

我收到BeanCreationExceptions,这是由于 Spring 启动时无法连接到定位器引起的:

4-Mar-2013 16:02:08.750 SEVERE org.apache.catalina.core.ApplicationContext.log StandardWrapper.Throwable
 org.springframework.beans.factory.BeanCreationException:
 [rest of stack trace snipped out]
 nested exception is com.gemstone.gemfire.GemFireConfigException: Unable to contact a Locator service.  Operation either timed out or Locator does not exist.
Configured list of locators is "[hostnameOfLocator<v0>:portOfLocator]".

但是当我部署到目标环境时,无法创建 Gemfire bean,因为定位器进程无法连接。我错过了什么?

【问题讨论】:

    标签: java spring spring-data gemfire spring-data-gemfire


    【解决方案1】:

    不看日志很难说。您的配置看起来不错。您在这些进程和 locator.log 中看到了哪些错误?

    我希望这些配置能够在应用服务器中启动定位器。

    这些配置不会启动定位器,只会连接到配置的定位器。但是您之前声明定位器已经启动。使用定位器时,mcast-port 也应始终为 0。

    一个常见的问题是 gemfire.jars 必须都是相同的版本。 SDGF 1.2.2 依赖于 gemfire 7.0。如果您使用的是 gemfire 6.6.1,则需要从 pom 中的 spring-data-gemfire 中排除 gemfire 依赖项。

    目标部署使用客户端服务器拓扑。

    此配置用于点对点。它应该仍然可以工作,但是如果您有现有的缓存服务器,您可能希望将其配置为客户端。该区域是服务器上 on 的副本还是仅是本地数据?请注意,如果您只需要@Cacheable,则不需要连接到网格。独立的嵌入式缓存可以正常工作。

    【讨论】:

    • 谢谢,戴夫! mcost-port 设置为 0。我已将 Gemfire 排除在 SDGF 1.2.2 加载之外。我确实尝试使用 连接到 的 Spring 配置,它使用预期的定位器主机名和端口,但我仍然得到相同的异常。
    • Dave,如果我只需要@Cacheable,有没有办法可以将 Gemfire 用作独立的嵌入式缓存?我的客户坚持我们只使用 Gemfire 作为我们的缓存提供程序,而不使用 EhCache 等其他提供程序。
    • 我还浏览了您在 github (github.com/SpringSource/spring-gemfire-examples) 上的 gemfire 示例,并在您使用 SDGF 1.2.1 时返回提交。我注意到replicated-cs 示例有一个与replicated-region 具有相同ID 的客户端区域。如果它们在同一个应用程序上下文中,那不会导致问题,对吧?
    【解决方案2】:

    您可以尝试配置定位器池,例如:

    <gfe:pool id="locatorPool">
        <gfe:locator host="host1" port="port1"/>
        <gfe:locator host="host2" port="port2"/>
    </gfe:pool>
    

    然后将你的缓存链接到这个池:

    <gfe:cache id="gemfireCache" pool-name="locatorPool"/>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-26
      • 2017-12-08
      • 1970-01-01
      • 1970-01-01
      • 2015-06-16
      • 1970-01-01
      相关资源
      最近更新 更多