之前遇到“缓存的对象变更后,自动更新到缓存中”的问题,参照http://blog.csdn.net/haiyang4988/article/details/53201618

然后就配置了copyOnWrite=“true”、copyOnRead=“true” 结果又出现了异常(缓存对象的时候)

net.sf.ehcache.CacheException: When configured copyOnRead or copyOnWrite, a Store will only accept Serializable values

最后是这样解决的,在ehcache.xml中配置

<cache name="conCache"  
           maxElementsOnDisk="20000"  
           maxElementsInMemory="5000"  
           eternal="true"  
           overflowToDisk="false"  
           diskPersistent="false"
           copyOnRead="true"
           copyOnWrite="true"
           memoryStoreEvictionPolicy="LRU">
           <copyStrategy class="com.xxx.MyCopyStrategy" />
           </cache>

然后MyCopyStrategy.java中代码如下

package com.xxxx.ehCache;import java.io.Serializable;import net.sf.ehcache.Element;
import net.sf.ehcache.store.compound.ReadWriteCopyStrategy;/** * 序列化要缓存的对象,否则设置  copyOnRead="true" copyOnWrite="true" 缓存对象的时候可能报序列化错误 * @author CUIJIAJUN** @date 2016年11月24日 下午2:52:03**/
public class MyCopyStrategy implements ReadWriteCopyStrategy<Element> {@Overridepublic Element copyForWrite(Element value) {if(value != null){
//          System.out.println("value==="+value);Object temp=(Serializable)value.getObjectValue();return new Element(value.getObjectKey(),temp);}return value;}@Overridepublic Element copyForRead(Element storedValue) {if(storedValue != null){
//          System.out.println("storedValue==="+storedValue);Object temp=(Serializable)storedValue.getObjectValue();return new Element(storedValue.getObjectKey(),temp);}return storedValue;}
}

ehcache 异常net.sf.ehcache.CacheException: When configured copyOnRead or copyOnWrite, a Store will onl相关推荐

  1. spring整合ehcache2.5.2缓存异常-- net.sf.ehcache.CacheException

    报错如下: The source of the existing CacheManager is: DefaultConfigurationSource [ ehcache.xml or ehcach ...

  2. shiro整合SSM使用ehcache出现的net.sf.ehcache.CacheException异常解决办法

    异常关键字 nested exception is org.apache.shiro.cache.CacheException: net.sf.ehcache.CacheException: java ...

  3. net.sf.ehcache.CacheException: java.io.OptionalDataException

    org.apache.shiro.cache.CacheException: org.apache.shiro.cache.CacheException: net.sf.ehcache.CacheEx ...

  4. updatechecker.java_Mybatis中出现net.sf.ehcache.util.UpdateChecker.checkForUpdate问题解决方案...

    问题描述 最近每次启动项目都会抛如下异常: 2018-03-29 09:01:07,831 DEBUG [ehcache] net.sf.ehcache.util.UpdateChecker.chec ...

  5. net.sf.ehcache.util.UpdateChecker

    解决问题: net.sf.ehcache.util.UpdateChecker:98] New update(s) found: 2.4.7 [http://www.terracotta.org/co ...

  6. spring security 3配置ACL时报java.lang.NoSuchMethodError: net.sf.ehcache.Cache.init

    严重: Exception sending context initialized event to listener instance of class org.springframework.we ...

  7. 使用‘net.sf.ehcache.CacheManager‘进行Shiro配置时报错

    注:作者水平有限,有错误请大佬及时评论纠正,谢谢! 1.首先说一下第一次报错: Error starting ApplicationContext. To display the conditions ...

  8. java.lang.NoClassDefFoundError: net/sf/ehcache/CacheManager

    错误信息如下: ption is java.lang.NoClassDefFoundError: net/sf/ehcache/CacheManager 10:29:34,433 ERROR Cont ...

  9. DEBUG [net.sf.ehcache.CacheManager@625732] - Update check failed:

    在使用ehcache缓存时,报如下错误. DEBUG [net.sf.ehcache.CacheManager@625732] - Update check failed: java.io.IOExc ...

最新文章

  1. 液冷数据中心再获加持,北京数据中心PUE要低至1.118
  2. MySQL sql99语法介绍
  3. Docker(二)-在Docker中部署Nginx实现负载均衡【完整教程】
  4. MongoDB学习3——mongoDB的一些基本使用
  5. 为什么现在越来越多的人不愿换新机?最后一个原因扎心了
  6. 解决一个用Idea的Docker插件远程部署SpringBoot的失败问题
  7. 如何删除管理员也无法删除的文件夹
  8. 卡莱特led显示屏调试教程_如何使用卡莱特软件点亮LED电子显示屏
  9. OpenFOAM常用类
  10. 程序员,你的身体还健康吗?
  11. qt QTableWidgetItem设置文字样式
  12. c# 开发文字识别软件
  13. 《清单革命》的读后感优秀范文3900字
  14. Debian备份与还原
  15. (建议收藏)服务器宕机了不要慌,这样排查效率高
  16. 中国土地市场网爬虫案例
  17. 首师大附中科创教育平台 我的刷题记录 0324 99999999海岛帝国:运输资源
  18. 谷歌手机pixel4 夜景_您应该购买Google Pixel 4a的5个理由
  19. MIT教授提出可扩展的新共识算法Algorand,彻底消除区块链分叉的可能性
  20. 一起探索西工大图书馆数字资源

热门文章

  1. 2022上半年软考电子证书查询已开通
  2. 几种常见的建模工具比较(ROSE、PowerDesigner、VISIO、EA)
  3. cmd命令卸载sql server_Ubuntu下部署SQL Server 2017(安装及使用方法,卸载方法)
  4. mysql学习第一弹——查询基础
  5. windows10系统下phpstudy安装php8版本
  6. 小doge的快乐阳光跑 //最短路+dp
  7. 【报告分享】互联网理财行为与安全研究报告-腾讯理财通xNFD(附下载)
  8. 物联网卡助力农牧业 提高智慧农业生产效率
  9. 在windows或linux中使用VIM/VI复制粘贴内容命令及设置大全
  10. Linux 配置Nginx环境变量Nginx常用命令