From 7019894f0ec7f6fd27121d94aa08022bd3040af9 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Tue, 4 Oct 2016 13:37:29 +0200 Subject: [PATCH] Clarify the role of spring-boot-starter-cache The cache abstraction is a core feature of the Spring Framework. Basic features such as `@EnableCaching` are therefore available by default with no extra dependencies necessary. However, the actual cache adapters for JCache, Ehcache 2.x, Caffeine and Guava are located in a separated module, `spring-context-support`. Spring Boot provides that artifact via the `spring-boot-starter-cache` starter. It is quite easy to "only" add the cache library dependencies and forget about this extra dependencies since `@EnableCaching` is available by default. This commit clarifies the role of the starer in each section so that it is more obvious. We're already explaining this at the beginning of the section but it seems that's not enough. Closes gh-7071 --- .../main/asciidoc/spring-boot-features.adoc | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc b/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc index 23c809eb6f..db0397ec68 100644 --- a/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc +++ b/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc @@ -3782,9 +3782,10 @@ enabled via the `@EnableCaching` annotation. NOTE: If you are using the cache infrastructure with beans that are not interface-based, make sure to enable the `proxyTargetClass` attribute of `@EnableCaching`. -TIP: Use the `spring-boot-starter-cache` '`Starter`' to quickly add required caching -dependencies. If you are adding dependencies manually you should note that certain -implementations are only provided by the `spring-context-support` jar. +TIP: Use the `spring-boot-starter-cache` '`Starter`' to quickly add basic caching +dependencies. The starter brings `spring-context-support`: if you are adding dependencies +manually, you must include it if you intend to use the JCache, EhCache 2.x or Guava +support. If you haven't defined a bean of type `CacheManager` or a `CacheResolver` named `cacheResolver` (see `CachingConfigurer`), Spring Boot tries to detect the following @@ -3842,9 +3843,10 @@ Generic caching is used if the context defines _at least_ one [[boot-features-caching-provider-jcache]] ==== JCache (JSR-107) JCache is bootstrapped via the presence of a `javax.cache.spi.CachingProvider` on the -classpath (i.e. a JSR-107 compliant caching library). There are various compliant +classpath (i.e. a JSR-107 compliant caching library) and the `JCacheCacheManager` +provided by the `spring-boot-starter-cache` '`Starter`'. There are various compliant libraries out there and Spring Boot provides dependency management for Ehcache 3, -Hazelcast and Infinispan). Any other compliant library can be added as well. +Hazelcast and Infinispan. Any other compliant library can be added as well. It might happen that more than one provider is present, in which case the provider must be explicitly specified. Even if the JSR-107 standard does not enforce a standardized @@ -3879,8 +3881,9 @@ abstraction expects. No further customization is applied on it. [[boot-features-caching-provider-ehcache2]] ==== EhCache 2.x EhCache 2.x is used if a file named `ehcache.xml` can be found at the root of the -classpath. If EhCache 2.x and such file is present it is used to bootstrap the cache -manager. An alternate configuration file can be provide a well using: +classpath. If EhCache 2.x, the `EhCacheCacheManager` provided by the +`spring-boot-starter-cache` '`Starter`' and such file is present it is used to bootstrap +the cache manager. An alternate configuration file can be provide a well using: [source,properties,indent=0] ---- @@ -3994,9 +3997,10 @@ recommend to keep this setting enabled if you create your own `RedisCacheManager [[boot-features-caching-provider-caffeine]] ==== Caffeine Caffeine is a Java 8 rewrite of Guava’s cache and will supersede the Guava support in -Spring Boot 2.0. If Caffeine is present, a `CaffeineCacheManager` is auto-configured. -Caches can be created on startup using the `spring.cache.cache-names` property and -customized by one of the following (in this order): +Spring Boot 2.0. If Caffeine is present, a `CaffeineCacheManager` (provided by the +`spring-boot-starter-cache` '`Starter`') is auto-configured. Caches can be created on +startup using the `spring.cache.cache-names` property and customized by one of the +following (in this order): 1. A cache spec defined by `spring.cache.caffeine.spec` 2. A `com.github.benmanes.caffeine.cache.CaffeineSpec` bean is defined