Another unnamed CacheManager already exists in the same VM.解决方法

来源:互联网 发布:剑三丐姐脸型数据 编辑:程序博客网 时间:2024/06/06 02:34
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.

出现这个错误,看源码


就是configuration.getName()的名字不为null或者为null就使用默认的


这里这个name的值是不是存在,不存在就给个默认的,存在就取这个name的值。

之后CACHE_MANAGERS_MAP这个map通过这个name的key值取获取值,如果获取不到就是null,那就添加,如果获取到了,就报上面那个错,说已经初始化过了。也就是跟你有没有写name其实没有关系。因为这个put添加操作只会在这里执行,所以报这个错就表明你的代码走了2次这个地方,已经添加过一次了,一般是初始化的时候初始化了2次

<property name="net.sf.ehcache.configurationResourceName" value="ehcache.xml" />这个类了

找到问题所在就找出我们在哪里初始化了2次这个地方

第一个地方,在配置文件里面初始化了c3p0,里面就有这个缓存类的初始化。


第二个地方,在basedao里面又初始化了一次c3p0,所以报错


所以注释掉它就可以了。

0 0
原创粉丝点击