EhCache and Spring – can’t find class EhCacheManagerFactoryBean?

I’m playing around with Spring and EhCache, and having a lot of fun. This problem stumped me for a few minutes as a lot of the tutorials I was playing around with didn’t mention a key dependency!

The Error

org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.cache.ehcache.EhCacheManagerFactoryBean] for bean with name 'cacheManager' defined in class path resource [application-context.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.cache.ehcache.EhCacheManagerFactoryBean
 at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1269)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:578)

The Missing Dependency…

<dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-context-support</artifactId>
   <version>${spring.version}</version>
</dependency>

You’ll also need two other core dependencies in addition to the standard Spring dependencies, but most tutorials/guides cover this:

<dependency>
   <groupId>com.googlecode.ehcache-spring-annotations</groupId>
   <artifactId>ehcache-spring-annotations</artifactId>
   <version>1.2.0</version>
</dependency>
<dependency>
   <groupId>net.sf.ehcache</groupId>
   <artifactId>ehcache</artifactId>
   <version>2.7.2</version>
</dependency>

As an aside, if you are looking for a great introduction and tutorial to using EhCache within Spring I can highly recommend Goyello’s Blog.

1 comment
  1. Wilson said:

    Nice tip! That missing dependency got me stuck until I found this!

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: