修改Spring中定义的EHCache bean

时间:2016-05-18 09:47:45

标签: java spring java-ee caching ehcache

假设Spring中有下面的缓存定义,是否可以通过单独的ehcache.xml文件或相同的xml文件设置bootstrapCacheLoaderFactory和cacheEventListenerFactory?如果我们在ehcache.xml的Cache定义中设置它们,那么将应用哪些缓存定义(在当前的xml文件或ehcache.xml中?)?

我在哪里可以为CacheManager设置cacheManagerPeerProviderFactory和cacheManagerPeerListenerFactory?

    <bean id="reportCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
        <property name="cacheManager" ref="cacheManager"/>
        <property name="maxElementsInMemory" value="${cache.report.maxMemoryElements}"/>
      </bean> 

<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
  <property name="configLocation" value="WEB-INF/ehcache.xml"/>

  </bean>

ehcache.xml中的以下标记是否有效?

 <cache name="reporteCache">
    <bootstrapCacheLoaderFactory class = "net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory" properties = "bootstrapAsynchronously=false, maximumChunkSizeBytes=5000000"/>

            <cacheEventListenerFactory class = "net.sf.ehcache.distribution.RMICacheReplicatorFactory" properties="replicateAsynchronously=true, asynchronousReplicationIntervalMillis=100"/>

       </cache>

xml和java代码都没问题。

提前谢谢。

1 个答案:

答案 0 :(得分:0)

以防其他人正在阅读此内容?您可以在ehcache.xml文件中设置cacheManagerPeerListenerFactory,如下所示

<cacheManagerPeerProviderFactory
        class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
        properties="peerDiscovery=automatic, multicastGroupAddress=230.0.0.2,
                multicastGroupPort=4455, timeToLive=1"/>
<cacheManagerPeerListenerFactory
        class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
        properties="host=hostname,port=40001, socketTimeoutMillis=2000"/>