缓存框架Ehcache学习(一)创建多个CacheManager抛出异常
2014-04-03 11:44
337 查看
最近在研究缓存框架Ehcache的配置和使用,我想根据多个ehcache.xml创建多个CacheManager对象,但是报了异常:
Caused by: net.sf.ehcache.CacheException: Another unnamed CacheManager already exists in the same VM. Please provide unique names for each CacheManager in the config or do one of following:
1. Use one of the CacheManager.create() static factory methods to reuse same CacheManager with same name or create one if necessary
2. Shutdown the earlier cacheManager before creating new one with same name.
错误提示很明显:Ehcache不允许创建同样名称的CacheManager对象。如果我们没有ehcache.xml中配置CacaheManager的名称,那么默认的名称是__DEFAULT__。解决方式是<ehcache name="">中配置CacheManager的名称,并确保唯一。这样如下代码就不会报错了
Caused by: net.sf.ehcache.CacheException: Another unnamed CacheManager already exists in the same VM. Please provide unique names for each CacheManager in the config or do one of following:
1. Use one of the CacheManager.create() static factory methods to reuse same CacheManager with same name or create one if necessary
2. Shutdown the earlier cacheManager before creating new one with same name.
错误提示很明显:Ehcache不允许创建同样名称的CacheManager对象。如果我们没有ehcache.xml中配置CacaheManager的名称,那么默认的名称是__DEFAULT__。解决方式是<ehcache name="">中配置CacheManager的名称,并确保唯一。这样如下代码就不会报错了
URL url = CacheHelper.class.getClassLoader().getResource("ehcache.xml"); CacheManager manager = new CacheManager(url); // __DEFAULT__ System.out.println(manager.getName()); URL url2 = CacheHelper.class.getClassLoader().getResource("ehcache2.xml"); CacheManager manager2 = new CacheManager(url2);
相关文章推荐
- 缓存框架Ehcache学习(二)多种创建CacheManager的方式
- 创建多个CacheManager抛出异常
- 业调度框架 Quartz 学习笔记(六) -- job生病了(抛出异常)时的处理
- Java缓存框架EhCache学习
- Mybatis学习(十四)mybatis框架下整合分布式缓存ehcache
- mybatis学习教程中级(十)mybatis和ehcache缓存框架整合(重点)
- 作业调度框架 Quartz 学习笔记(六) -- job生病了(抛出异常)时的处理
- JavaWeb学习笔记-spring-12-AOP-创建增强类(异常抛出增强)
- 框架与Window对象 学习笔记(一): 创建多个框架
- 作业调度框架 Quartz 学习笔记(六) -- job生病了(抛出异常)时的处理
- 作业调度框架 Quartz 学习笔记(六) -- job生病了(抛出异常)时的处理
- EhCache缓存框架学习笔记
- Android:java 抛出异常throw与throws以及捕捉异常try、catch、finally学习
- EHcache缓存框架详解
- 学习MFC框架如何创建的过程
- iOS超全开源框架、项目和学习资料汇总--数据库、缓存处理、图像浏览、摄像照相视频音频篇
- EhCache缓存框架(3)-EhCache 常用配置项详解
- OAF学习笔记-16-自定义异常的抛出
- ehcache 与spring相结合超时自动刷新缓存的框架搭建
- CVP认证学习笔记--李天宇016使用纹理缓存创建精灵