【问题标题】:Another CacheManager with same name 'cacheManager' already exists in the same VM同一个虚拟机中已经存在另一个同名 'cacheManager' 的 CacheManager
【发布时间】:2017-01-27 10:47:09
【问题描述】:

我在使用 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.
  • 春季 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>

缓存上下文.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>

有什么建议吗? 谢谢!

【问题讨论】:

    标签: spring caching ehcache


    【解决方案1】:

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

    您可能需要提供 ehcache.xml 或设置缓存名称,否则您可以看到 here

    编辑:ApplicationContext 加载了两次

    如果你遇到了断点,向上走堆栈跟踪,你可能会发现为什么 spring 加载了两次上下文。

    【讨论】:

    • 感谢您的回答。我以前检查过那些。我的 ehcache.xml 有一个名字。调试我看到上下文可能被加载了两次,我不确定,我看到正在尝试使用相同的名称注册相同的cacheManager。
    • 我偶然发现了 edit 选项,但我不知道如何识别 why 加载两次。有什么额外的建议吗?
    【解决方案2】:

    有两种可能。

    1. 在 semesever 上安装了具有相同缓存名称的其他应用程序
    2. 由于 ContextLoaderListener 的原因,启动服务器时应用程序可能会部署两次。所以从你的 web.xml 中删除 ContextLoaderListener。

    【讨论】:

      【解决方案3】:

      以下将解决问题:

      hibernate.cache.region.factory_class = org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory
      
      hibernate.cache.provider_class = net.sf.ehcache.hibernate.SingletonEhCacheProvider
      

      【讨论】:

        猜你喜欢
        • 2012-04-18
        • 2015-06-29
        • 1970-01-01
        • 2013-03-17
        • 2012-06-23
        • 2015-10-10
        • 1970-01-01
        • 2018-01-31
        • 2021-04-27
        相关资源
        最近更新 更多