同一虚拟机中已经存在一个名称为“cacheManager”的另一个CacheManager。

6
当我使用ehcache和Spring启动tomcat时,出现了这个错误。
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.
  • Spring 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>

cache-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>

我有一个旧的依赖项hibernate-ehcache,不幸的是我无法删除它。这可能是问题所在吗?

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

有什么建议吗? 谢谢!

3个回答

0

这里讨论了一些解决方案这里

你可能需要提供一个ehcache.xml或设置缓存名称,否则就像你看到的那样这里

编辑:ApplicationContext 加载两次

如果你遇到断点,请回溯堆栈跟踪,你可能会发现为什么Spring会加载上下文两次。


谢谢回答。我之前已经检查过了。我的ehcache.xml有一个名称。调试时我发现上下文可能会被加载两次,我不确定,但我看到它正在尝试使用相同的名称注册相同的cacheManager。 - Fernando A.
我遇到了_edit_选项,但我不知道如何确定为什么会加载两次。有什么额外的建议吗? - lucasvc

0

有两种可能性。

  1. 在同一缓存名称下安装了其他应用程序
  2. 由于ContextLoaderListener,当您启动服务器时,应用程序可能会部署两次。因此,请从您的web.xml中删除ContextLoaderListener。

0
以下方法可以解决这个问题:
hibernate.cache.region.factory_class = org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory

hibernate.cache.provider_class = net.sf.ehcache.hibernate.SingletonEhCacheProvider

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接