我在项目用中用到了apache shiro安全框架,并使用了官网推荐的Ehcache做集群session同步是成功的,但是当我使用Ehcache同步数据的时候失败了,使用了RMI,也按照官网在配置了,当我在本地做测试的时候RMI 是好用的,但是放到Tomcat上跑,就不可以了,后台也不抛错,擦。。郁闷了,哪位大神帮帮我,用什么方法可以看到RMI 是否通信了,怎么来调试一下。下面是我的配置信息
节点一:
<cacheManagerPeerProviderFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
properties="peerDiscovery=manual,
rmiUrls=//192.168.1.90:40001/shiroCache"/>
<cacheManagerPeerListenerFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
properties="hostName=localhost, port=40002,
socketTimeoutMillis=2000"/>
<defaultCache maxElementsInMemory="10000" eternal="false"
timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="true"
diskSpoolBufferSizeMB="30" maxElementsOnDisk="10000000"
diskPersistent="false" diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU">
<cacheEventListenerFactory
class="net.sf.ehcache.distribution.RMICacheReplicatorFactory" />
</defaultCache>
<cache name="shiroCache" maxElementsInMemory="1000" eternal="false"
timeToIdleSeconds="100000" timeToLiveSeconds="100000"
overflowToDisk="false">
<cacheEventListenerFactory
class="net.sf.ehcache.distribution.RMICacheReplicatorFactory" />
</cache>
</ehcache>
节点二:
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../config/ehcache.xsd">
<cacheManagerPeerProviderFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
properties="peerDiscovery=manual,
rmiUrls=//192.168.1.90:40002/shiroCache"/>
<cacheManagerPeerListenerFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
properties="hostName=localhost, port=40001,
socketTimeoutMillis=2000"/>
<defaultCache maxElementsInMemory="10000" eternal="false"
timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="true"
diskSpoolBufferSizeMB="30" maxElementsOnDisk="10000000"
diskPersistent="false" diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU">
<cacheEventListenerFactory
class="net.sf.ehcache.distribution.RMICacheReplicatorFactory" />
</defaultCache>
<cache name="shiroCache" maxElementsInMemory="1000" eternal="false"
timeToIdleSeconds="100000" timeToLiveSeconds="100000"
overflowToDisk="false">
<cacheEventListenerFactory
class="net.sf.ehcache.distribution.RMICacheReplicatorFactory" />
</cache>
</ehcache>
spring的配置:
<bean id="cacheManager" class="org.apache.shiro.cache.ehcache.EhCacheManager" >
<property name="cacheManager" ref="ehCacheManager"/>
<property name="cacheManagerConfigFile" value="ehcache-shiro.xml" />
</bean>
<bean id="ehCacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"/>
在项目的调用:
CacheManager cacheManager = ApplicationContextAccessor.getBean("cacheManager");
Cache<Object, Object> shiroCache = cacheManager.getCache("shiroCache");