ehcache configuration in Spring framework ehcache configuration in Spring framework spring spring

ehcache configuration in Spring framework


This class is located in the spring-context-support module that is optional. Please make sure that you have added it as a dependency of your project.

<dependency>   <groupId>org.springframework</groupId>   <artifactId>spring-context-support</artifactId>   <version>X.Y.Z.RELEASE</version></dependency>


Your spring configuration is excellent, i see examples with lots of typos on the web.

<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager" p:cache-manager-ref="ehcache" /><bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" p:configLocation="/WEB-INF/ehcache.xml" />

Remark: you need both dependencies:

<dependency>    <groupId>net.sf.ehcache</groupId>    <artifactId>ehcache</artifactId>    <version>2.8.3</version></dependency><dependency>   <groupId>org.springframework</groupId>   <artifactId>spring-context-support</artifactId>   <version>3.2.8.RELEASE</version></dependency>

first one is implementation second one is spring wrapper around it. If you don't use both you will have exceptions related to finding implementing class.


Use below maven dependency in your pom.xml

<dependency>        <groupId>org.springframework</groupId>        <artifactId>spring-context</artifactId>        <scope>compile</scope>    </dependency>    <dependency>        <groupId>org.springframework</groupId>        <artifactId>spring-context-support</artifactId>        <version>4.3.4.RELEASE</version>    </dependency>

Also, make sure that you use version 4.3.4. Don't use 5.0.6 and other latest version, It didn't work for me.