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

Fer*_*A. 5 spring caching ehcache

使用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.
Run Code Online (Sandbox Code Playgroud)
  • 春季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>
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

我确实对hibernate-ehcache有旧的依赖,但是不幸的是我无法删除。这可能是问题吗?

  <dependency>
                   <groupId>org.hibernate</groupId>
                   <artifactId>hibernate-ehcache</artifactId>
                   <version>3.5.0-Final</version>
               </dependency>
Run Code Online (Sandbox Code Playgroud)

有什么建议么?谢谢!

Ste*_*com 0

这里讨论了一些解决方案

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

编辑:ApplicationContext 加载两次

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