Allow auto-configured caches to be overridden

This commit updates the JSR 107 cache auto-configuration to only create
a cache if it does not already exist. It also puts a specific order for
the auto-configured customizer so that another instance can run prior to
it reliably.

Closes gh-1157
This commit is contained in:
Stephane Nicoll
2020-12-08 15:32:37 +01:00
parent 7cb9f5bcaf
commit 8d61cdd6aa
4 changed files with 92 additions and 10 deletions

View File

@@ -1143,6 +1143,9 @@ checking for the latest Spring Boot versions too often, you should enable cachin
service. Spring Initializr has some auto-configuration to apply the proper caches if you
are willing to use a JCache (JSR-107) implementation.
NOTE: The caches are created with an auto-configured `JCacheManagerCustomizer` with order `0` and only if they don't exist already.
You can contribute a bean of the same type with a lower `@Order` to override some of the configuration to suit your specific needs.
Add the `javax.cache:cache-api` and your favorite JCache implementation and simply enable
caching by adding `@EnableCaching` to your `@SpringBootApplication`. For instance, you
could use `ehcache` by adding the following: