快速业务通道

iBatis使用OSCache作缓存与java.io.FileNotFoundException异常 - 编程入门网

作者 佚名技术 来源 NET编程 浏览 发布时间 2012-06-20

iBatis使用OSCache作缓存与java.io.FileNotFoundException异常

时间:2011-01-17 隔叶黄莺

这种异常只会发生在 Windows 平台上,可以说是 iBatis 的一个 Bug,大约 iBatis 的开发测试人员都比较热衷于 Unix 族系的平台,而忽略了 Windows 下的兼容性测试。

出现 FileNotFoundException 异常的情形是这样的:Windows7 + iBatis2.3.0.677 + OSCache2.4.1。

iBatis 中配置使用 OSCache 缓存,在映射文件 Product.xml 中有如下声明片断:

1.<cacheModel type="OSCACHE" id="productCache"> 2.<flushOnExecute statement="Product.insert"/> 3.<flushOnExecute statement="Product.delete"/> 4.</cacheModel> 5. 6.<select id="getById" cacheModel="productCache" parameterClass="int" resultClass="Product"> 7.select id, name,description as desc1  from test_product where id = #value# 8.</select>

OSCache 的 oscache.properties 中指明用磁盘文件缓存数据,注意以下几个配置:

01.#不缓存到内存 02.cache.memory=false 03. 04.#缓存持久化实现类,磁盘持久化监听器 05.cache.persistence.class=com.opensymphony.oscache.plugins.diskpersistence.DiskPersistenceListener 06. 07.#缓存磁盘路径,以后注意观察该目录生成的内容 08.cache.path=e:\\OSCache\\cache 09. 10.#选择一种缓存算法,还可选 FIFOCache、UnlimitedCache 11.cache.algorithm=com.opensymphony.oscache.base.algorithm.LRUCache

Java 测试代码:

1.public static void main(String[] args) throws Exception{ 2.Reader reader = Resources.getResourceAsReader("SqlMapConfig.xml"); 3.SqlMapClient sqlMapClient = SqlMapClientBuilder.buildSqlMapClient(reader); 4.System.out.println(sqlMapClient.queryForObject("Product.getById",5)); 5. 6.//后面同样的查询将不再查询数据库,而是直接使用前面执行放在缓存中的内容 7.System.out.println(sqlMapClient.queryForObject("Product.getById",5)); 8.}

执行上面那段代码,你将会得到异常:

2009-8-19 10:45:52 com.opensymphony.oscache.base.algorithm.AbstractConcurrentReadCache persistStore 严重: [oscache] Exception persisting 1991729862|2162672802|5|Product.getById|62996507|         select id, name,description as desc1  from test_product where id = ?     |executeQueryForObject com.opensymphony.oscache.base.persistence.CachePersistenceException: Unable to write ''e:\OSCache\cache\application\1991729862|2162672802|5|Product_31getById|62996507|_49_50_51_52_53_54_55_56_57select_64id,_68name,description_85as_88desc1_94_95from_100test_105product_113where_119id_122=_124_125_126_127_128_129_130|executeQueryForObject.cache'' in the cache.Exception: java.io.FileNotFoundException, Message: e:\OSCache\cache\application\1991729862|2162672802|5|Product_31getById|62996507|_49_50_51_52_53_54_55_56_57select_64id,_68name,description_85as_88desc1_94_95from_100test_105product_113where_119id_122=_124_125_126_127_128_129_130|executeQueryForObject.cache (文件名、目录名或卷标语法不正确。) at com.opensymphony.oscache.plugins.diskpersistence.AbstractDiskPersistenceLis

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号