最近2天一直在Spring2.5.6 配置ehcache缓存,结果总是出错,后经过高手帮助找到原因所在:
1. spring2.5.6配置ehcache1.5版本,否则出现java.lang.NullPointerException at net.sf.cache.CacheManager.init()
2. 添加backpot-util-concurrent.jar
3. ehcache.xml中的defaultCache是默认配置,不能删除,否则报错
经过调试,最后配置内容如下:
ehcache.xml:
<?xml version="1.0" encoding="UTF-8"?>
<ehcache>
<diskStore path="c:/ehcache" />
<cache name="com.hspc.egtl.METHOD_CACHE" maxElementsInMemory="1000"
eternal="false" timeToIdleSeconds="500" timeToLiveSeconds="500"
overflowToDisk="true" maxElementsOnDisk="1000" diskPersistent="false"
diskExpiryThreadIntervalSeconds="120" memoryStoreEvictionPolicy="LRU" />
<defaultCache maxElementsInMemory="10000" eternal="false"
timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="true"
maxElementsOnDisk="10000000" diskPersistent="false"
diskExpiryThreadIntervalSeconds="120" memoryStoreEvictionPolicy="LRU" />
</ehcache>
applicationContext.xml
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation">
<value>classpath:ehcache.xml</value>
</property>
</bean>
<bean id="methodCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
<property name="cacheManager">
<ref local="cacheManager"/>
</property>
<property name="cacheName">
<value>com.hspc.egtl.METHOD_CACHE</value>
</property>
</bean>