Spring JUnit Ehcache: Hibernate Second-Level Caching: Another unnamed CacheManager already exists in the same VM.

If you are quite simply trying to introduce Hibernate second level caching into your Spring based application using Ehcache, you may end up banging your head against this wall when running your Junit tests: Another unnamed CacheManager already exists in the same VM.

Even worse, you may get sidetracked by posts such as this one which has to do with Spring 3.1 caching.

It may be that you have decided to included a version of Ehcache > 2.5, if that is the case, then before wasting more time on this, like I did, downgrade to Ehcache 2.4.7:

BEFORE

<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-core</artifactId>
<version>2.5.2</version>
</dependency>

AFTER

<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-core</artifactId>
<version>2.4.7</version>
</dependency>

One more tip, to get started with you ehcache.xml config, copy the defaults in ehcache-failsafe.xml and go from there, dump the file in your resources folder in your project and consult the Ehcache Hibernate Second-Level Cache Documentation.

Advertisements

One thought on “Spring JUnit Ehcache: Hibernate Second-Level Caching: Another unnamed CacheManager already exists in the same VM.

  1. Thank you for this post! it really helps me during some trouble with junit and other stuff .. then i found that you could also shutdown cachemanager in a teardown method to clean cache for the next test in this way:

    import net.sf.ehcache.CacheManager;
    CacheManager.getInstance().shutdown();

    hope it could help!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s