6

I receive this error when starting tomcat with ehcache and Spring.

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
  • No test context using this.
  • This is a web JSF app.

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>

I do have and old dependency to hibernate-ehcache, that unfortunately I can not delete. Could this be the issue?

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

Any suggestions? Thank you!

Fernando A.
  • 61
  • 1
  • 1
  • 2

3 Answers3

0

Some solutions are discussed here here

and you might need to provide a ehcache.xml or set the cache name otherwise as you can see here

Edit : ApplicationContext loaded twice

If you hit the breakpoint, go up the stacktrace and you may discover why spring is loading the context twice.

Community
  • 1
  • 1
  • Thanks for the answer. I checked those before. My ehcache.xml has a name. Debugging I see that the context may be loaded twice, I'm not sure, I see is trying to register the same cacheManager with the same name. – Fernando A. Sep 19 '16 at 19:10
  • I've stumbled with the _edit_ option, but I don't know how to identify **why** is loading twice. Any extra advice? – lucasvc Jul 03 '20 at 07:55
0

There are two possiblites.

  1. someother application installed on the semesever with same cache name
  2. Application may deployed twice when you start the server due to ContextLoaderListener. So remove ContextLoaderListener from your web.xml.
Thom
  • 14,013
  • 25
  • 105
  • 185
Selvam Rajendran
  • 1,366
  • 5
  • 20
  • 38
0

Following will solve the problem:

hibernate.cache.region.factory_class = org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory

hibernate.cache.provider_class = net.sf.ehcache.hibernate.SingletonEhCacheProvider
ParisaN
  • 1,816
  • 2
  • 23
  • 55