【问题标题】:Cache refresh is showing error with @cacheable annotation缓存刷新显示带有@cacheable 注释的错误
【发布时间】:2015-05-13 00:44:46
【问题描述】:

谁能帮我调试一下这个错误?

2015-03-11 14:59:03,844 [cachename.data] 错误 n.s.e.store.disk.DiskStorageFactory - 磁盘写入 -351643849550012 失败:java.io.NotSerializableException: com.googlecode.ehcache.annotations.RefreshableCacheEntry 在 java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1164) ~[na:1.6.0_45] 在 java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1518) ~[na:1.6.0_45] 在 java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:422) ~[na:1.6.0_45] 在 net.sf.ehcache.Element.writeObject(Element.java:867) ~[ehcache-2.8.1.jar:2.8.1] 在 sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法) ~[na:1.6.0_45] 在 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) ~[na:1.6.0_45] 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[na:1.6.0_45] 在 java.lang.reflect.Method.invoke(Method.java:597) ~[na:1.6.0_45] 在 java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:940) ~[na:1.6.0_45] 在 java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1469) ~[na:1.6.0_45] 在 java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1400) ~[na:1.6.0_45] 在 java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1158) ~[na:1.6.0_45] 在 java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:330) ~[na:1.6.0_45] 在 net.sf.ehcache.util.MemoryEfficientByteArrayOutputStream.serialize(MemoryEfficientByteArrayOutputStream.java:97) ~[ehcache-2.8.1.jar:2.8.1] 在 net.sf.ehcache.store.disk.DiskStorageFactory.serializeElement(DiskStorageFactory.java:399) ~[ehcache-2.8.1.jar:2.8.1] 在 net.sf.ehcache.store.disk.DiskStorageFactory.write(DiskStorageFactory.java:381) ~[ehcache-2.8.1.jar:2.8.1] 在 net.sf.ehcache.store.disk.DiskStorageFactory$DiskWriteTask.call(DiskStorageFactory.java:473) ~[ehcache-2.8.1.jar:2.8.1] 在 net.sf.ehcache.store.disk.DiskStorageFactory$PersistentDiskWriteTask.call(DiskStorageFactory.java:1067) [ehcache-2.8.1.jar:2.8.1] 在 net.sf.ehcache.store.disk.DiskStorageFactory$PersistentDiskWriteTask.call(DiskStorageFactory.java:1051) [ehcache-2.8.1.jar:2.8.1] 在 java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) [na:1.6.0_45] 在 java.util.concurrent.FutureTask.run(FutureTask.java:138) [na:1.6.0_45] 在 java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:98) [na:1.6.0_45] 在 java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:206) [na:1.6.0_45] 在 java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895) [na:1.6.0_45] 在 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918) [na:1.6.0_45] 在 java.lang.Thread.run(Thread.java:662) [na:1.6.0_45]

我正在使用带有@cacheable 注释的缓存刷新:

CacheFetchDao.java

@Cacheable(cacheName = "cachename",refreshInterval=10000, decoratedCacheType= DecoratedCacheType.REFRESHING_SELF_POPULATING_CACHE)
//@Cacheable( value = "cachename", key = "#key")
public List<Account> getAccounts(String key) {
    //call to database
    return res;
}

CachefetchEndpoint.java

    @GET
@Path("/Accounts")
@WebMethod(operationName = "Accounts")
public List<Account> Accounts() {
    return dao.getAccounts("accounts");
}

ehcache.xml

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="ehcache.xsd" 
    updateCheck="true"
    monitoring="autodetect" 
    dynamicConfig="true">

    <diskStore path="java.io.tmpdir"/>  

    <defaultCache    
        maxElementsInMemory="100"  
        eternal="false"    
        timeToIdleSeconds="120"    
        timeToLiveSeconds="120"    
        overflowToDisk="true"    
        diskSpoolBufferSizeMB="30"    
        maxElementsOnDisk="10000000"    
        diskPersistent="false"    
        diskExpiryThreadIntervalSeconds="120"    
        memoryStoreEvictionPolicy="LRU"/>  

    <!-- The cache configuration for our Currency cache -->  
    <cache name="cachename"  
        maxElementsInMemory="3000"  
        eternal="false" 
        timeToIdleSeconds="120"  
        timeToLiveSeconds="120"  
        <persistence strategy="localTempSwap"/>
    </cache>  
</ehcache>  

和 config.xml

 <ehcache:annotation-driven cache-manager="ehcache" />

<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
        <property name="cacheManager" ref="ehcache" />
        </bean>

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

【问题讨论】:

    标签: java spring caching ehcache


    【解决方案1】:

    我希望你的 Account Type 实现 Serializable 接口 ?你也可以发一下吗?

    【讨论】:

    • public final class Account实现Serializable{ ...attributes+ getter +setter }
    • 您的帐户对象是否包含其他可能未实现可序列化的类型?从异常来看,很明显有人没有实现 Serializable,因此 java io 无法将该对象持久保存到磁盘。
    • Account 类中只有 String 和 Double。
    • 调用数据库查询是 List res = new NamedParameterJdbcTemplate(source).query(select.toString(), empty, new AccountRowMapper2());
    • 我可以在几个小时后为您提供日志(现在远离系统),但似乎这是code.google.com/p/ehcache-spring-annotations/issues/… 我面临的问题。
    【解决方案2】:

    我通过删除 diskPersistent="false" 解决了这个问题。 diskPersistent="false" 不能与 decoratedCacheType= DecoratedCacheType.REFRESHING_SELF_POPULATING_CACHE 一起使用

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-05-06
      • 1970-01-01
      • 2021-06-08
      • 1970-01-01
      • 2012-08-20
      • 2013-07-17
      • 2019-03-09
      相关资源
      最近更新 更多