0

I am new to spring boot project. Currently I am working on a project with spring boot, Jcache with ehcache implementation.

I am trying to understand how spring boot autoconfigures the Cache Framework. I did my own research and identified spring boot @EnableAutoConfiguration reads the spring.factories file and autoconfigures the Cache related beans based on the classes available in classpath.

Here is the Spring Boot Cache auto configure Java based Configuration file available under spring.factories file

org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration,\

but for Jcache “ JCacheCacheConfiguration.java” is the Spring Boot auto configuration file , But this file is not available under spring.factroies file in autoconfigurer.jar file.

Then how spring boot auto configures the Jcache without entry in spring.factories file?

Madhu
  • 552
  • 2
  • 10
  • 23

1 Answers1

3

JCache implementations are providing a service (in META-INF). So Spring can found the implementation magically. The simpler is @EnableCaching which will find the provider and give you caching right away.

Then, you will want to provide a specific caching configuration. The easiest is by specifying spring.cache.jcache.config=ehcache.xml in your application.properties.

That's it. You will find a more complicated and Java (no xml) configuration in ehcache sample and pet clinic.

Henri
  • 5,551
  • 1
  • 22
  • 29
  • Thank you for sharing the pet clinic example. Helped to see how Ehcache could be configured through Java-based configuration. – Erikson May 31 '18 at 14:47