1. 程式人生 > >Another unnamed CacheManager already exists in the same VM.解決方法

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

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,所以報錯


所以註釋掉它就可以了。