ehcache从1.2版本开始支持分布式缓存,所以要将使用的jar包升级为1.2+在cache.xml(ehcache的配置文件)中加入<cacheManagerPeerProviderFactory class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory" properties="peerDiscovery=automatic, multicastGroupAddress=230.0.0.1, multicastGroupPort=4446"/><cacheManagerPeerListenerFactory class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"/>另外在每个cache属性中加入<cacheEventListenerFactory class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"/>例如:<cache name="a" maxElementsInMemory="10000" eternal="true" overflowToDisk="true"> <cacheEventListenerFactory class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"/></cache> |