有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Spring数据配置未连接到定位器?

假设我有Gemfire定位器&;cacheserver进程已在我的目标部署环境中运行。目标部署环境使用client-server topology

我有一个Spring3.1MVC应用程序,它希望使用Gemfire缓存。我使用的是Spring数据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应该能够使用新的缓存区域

我得到的BeanCreationException是由于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无法创建,因为定位器进程无法连接。我错过了什么


共 (2) 个答案

  1. # 1 楼答案

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

    <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"/>
    
  2. # 2 楼答案

    很难说没有看到日志。你的配置看起来不错。在这些过程和定位器中,您看到了哪些错误。日志

    I expect these configurations to start up a locator in the application server.

    这些配置不会启动定位器,只会连接到已配置的定位器。但是你之前说定位器已经启动了。此外,在使用定位器时,mcast端口应始终为0

    一个常见的问题是火灾。罐子必须是同一个版本。SDGF 1.2.2取决于gemfire 7.0。如果您使用的是gemfire 6.6.1,则需要从pom中的spring数据gemfire中排除gemfire依赖项

    The target deployment uses a client server topology.

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