2016-09-19 292 views
1

當使用ehcache和Spring啓動tomcat時收到此錯誤。具有相同名稱'cacheManager'的另一個CacheManager已經存在於同一虛擬機中

Another CacheManager with same name '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. 
  • 春3.1
  • 的Ehcache 2.9.0
  • 使用這個沒有測試環境。
  • 這是一個Web JSF應用程序。

ehcache.xml中

  <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xsi:noNamespaceSchemaLocation="ehcache.xsd" 
      updateCheck="true" 
      monitoring="autodetect" 
      dynamicConfig="true" 
      name="ehcacheManager" 
      > 
     .... 

    </ehcache> 

緩存的context.xml

 <bean id="cacheManager" 

     class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" scope="singleton"> 
       <property name="shared" value="true"/> 
       <property name="configLocation"> 
        <value>classpath:ehcache.xml</value> 
       </property> 
      </bean> 

我有老依賴冬眠-ehcache的,很遺憾,我不能刪除。這可能是問題嗎?

<dependency> 
        <groupId>org.hibernate</groupId> 
        <artifactId>hibernate-ehcache</artifactId> 
        <version>3.5.0-Final</version> 
       </dependency> 

有什麼建議嗎? 謝謝!

回答

0

有些解決方案在這裏討論here

,你可能需要提供一個ehcache.xml中或以其他方式設置緩存的名字,你可以看到here

編輯:ApplicationContext中加載兩次

如果你點擊了斷點,那麼就上棧跟蹤,你可能會發現爲什麼spring會加載上下文兩次。

+0

感謝您的回答。我之前檢查過這些。我的ehcache.xml有一個名字。調試我發現上下文可能會被加載兩次,我不確定,我看到的是嘗試註冊具有相同名稱的同一個cacheManager。 –

0

有兩種可能性。當你啓動服務器由於ContextLoaderListener的

  1. 與同抓名稱
  2. 應用的semesever一些其它應用程序安裝可部署的兩倍。所以從web.xml中移除ContextLoaderListener。
相關問題