Spring boot with Ehcache 3 and JSR-107

Here we are going to cover how to use Ehcache 3 as a Spring cachingĀ  in Spring boot based into JSR-107, before we start we need to just highlight what us JSR-107 :

JSR-107(JCache) Annotations:

In regards to caching, Spring offers support for two sets of annotations that can be used to implement caching. You have the original Spring annotations and the new JSR-107 annotations, for more information you can check :


Steps to use EhCache3 with Spring boot :

1- Create a spring boot maven project

2- Add the following maven dependencies in your pom.xml along with spring boot dependencies

3- Set the spring.cache.jcache.config property to include the classpath and ehcache.xml file, enable the following in application.yml file

Screen Shot 2017-12-22 at 15.55.12.png

4- Enable caching in spring boot main class

5- Configure your EhCache xml file as the following

6- Then you can easily inject the cache manger in your bean class if you do not want to use just simple annotations to enable caching for your operations

7- Start accessing your caches from cache manager if you want to do direct operation over it like below , please check EhcacheAlertsStore.java in the GitHub project for more information

8- Complete code sample for testing is on GitHub where you can run it and play with the REST APIs for cache operations via the generated run-time swagger :



References :