Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using ehcache 3 with Spring Annotations (not using Spring Boot)

I'm trying to get Ehcache 3 working with Spring 4 without using Spring boot.

Here is a working example out there which uses Spring Boot, but I'm working on an existing application which is not using Spring Boot.

The problem is that spring-context-support (which adds Spring's cache annotations) expects the Ehcache's CacheManager to be on this classpath: net.sf.ehcache.CacheManager

However, in Ehcache 3, the CacheManager class resides on another classpath: org.ehcache.CacheManager.

So, basically spring-context-support does not support Ehcache 3. And you would have to use the JSR-107 annotations directly, not the annotations provided by Spring.

But apparently it works with Spring Boot. Perhaps there is a way to make it work with a standard Spring Application as well. That's what I'm hoping. I really want to be using Spring's own annotations instead of the JSR-107 annotations.

like image 677
Håvard Geithus Avatar asked Sep 08 '16 09:09

Håvard Geithus


2 Answers

Indeed there is no native support of Ehcache 3 in Spring Caching.

The good news is that you achieve what you want with the JCache support that Spring Caching has since Ehcache 3 is a compliant JCache implementation. And once you have a JCache CacheManager available in your application context, nothing forces you to use the JCache annotations. You can keep using the Spring Caching ones without any problem.

You can find a demo of that here.

Note: I am working on Ehcache

like image 134
Louis Jacomet Avatar answered Oct 11 '22 10:10

Louis Jacomet


This is simple and working sample for all needed changes from ehcache 2 to 3: https://imhoratiu.wordpress.com/2017/01/26/spring-4-with-ehcache-3-how-to/

This this is link for new configuration:

  • http://www.ehcache.org/documentation/3.4/xml.html
  • http://www.ehcache.org/documentation/3.1/107.html#supplement-jsr-107-configurations
like image 4
Grigory Kislin Avatar answered Oct 11 '22 11:10

Grigory Kislin