Favor JSR-107 provider if present
Previously, native cache libraries were favored over a standard JSR-107 implementation. If a user has a working setup using JCache with one provider and switch to another provider, his setup may be broken if we happen to provide a native support for the new provider. We now consistently favor JSR-107 if it is present. Native support can still be enabled via the `spring.cache.type` property. Closes gh-3822
This commit is contained in:
@@ -2806,10 +2806,10 @@ implementations are only provided by the `spring-context-support` jar.
|
||||
Spring Boot tries to detect the following providers (in this order):
|
||||
|
||||
* <<boot-features-caching-provider-generic,Generic>>
|
||||
* <<boot-features-caching-provider-jcache,JCache (JSR-107)>>
|
||||
* <<boot-features-caching-provider-ehcache2,EhCache 2.x>>
|
||||
* <<boot-features-caching-provider-hazelcast,Hazelcast>>
|
||||
* <<boot-features-caching-provider-infinispan,Infinispan>>
|
||||
* <<boot-features-caching-provider-jcache,JCache (JSR-107)>>
|
||||
* <<boot-features-caching-provider-redis,Redis>>
|
||||
* <<boot-features-caching-provider-guava,Guava>>
|
||||
* <<boot-features-caching-provider-simple,Simple>>
|
||||
@@ -2826,6 +2826,38 @@ Generic caching is used if the context defines _at least_ one
|
||||
|
||||
|
||||
|
||||
[[boot-features-caching-provider-jcache]]
|
||||
==== JCache
|
||||
JCache is bootstrapped via the presence of a `javax.cache.spi.CachingProvider` on the
|
||||
classpath (i.e. a JSR-107 compliant caching library). It might happen than more that one
|
||||
provider is present, in which case the provider must be explicitly specified. Even if the
|
||||
JSR-107 standard does not enforce a standardized way to define the location of the
|
||||
configuration file, Spring Boot does its best to accommodate with implementation details.
|
||||
|
||||
[source,properties,indent=0]
|
||||
----
|
||||
# Only necessary if more than one provider is present
|
||||
spring.cache.jcache.provider=com.acme.MyCachingProvider
|
||||
spring.cache.jcache.config=classpath:acme.xml
|
||||
----
|
||||
|
||||
NOTE: Since a cache library may offer both a native implementation and JSR-107 support
|
||||
Spring Boot will prefer the JSR-107 support so that the same features are available if
|
||||
you switch to a different JSR-107 implementation.
|
||||
|
||||
There are several ways to customize the underlying `javax.cache.cacheManager`:
|
||||
|
||||
* Caches can be created on startup via the `spring.cache.cache-names` property. If a custom
|
||||
`javax.cache.configuration.Configuration` bean is defined, it is used to customize them.
|
||||
* `org.springframework.boot.autoconfigure.cache.JCacheManagerCustomizer` beans are
|
||||
invoked with the reference of the `CacheManager` for full customization.
|
||||
|
||||
TIP: If a standard `javax.cache.CacheManager` bean is defined, it is wrapped
|
||||
automatically in a `org.springframework.cache.CacheManager` implementation that the
|
||||
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
|
||||
@@ -2868,38 +2900,6 @@ Caches can be created on startup via the `spring.cache.cache-names` property. If
|
||||
|
||||
|
||||
|
||||
[[boot-features-caching-provider-jcache]]
|
||||
==== JCache
|
||||
JCache is bootstrapped via the presence of a `javax.cache.spi.CachingProvider` on the
|
||||
classpath (i.e. a JSR-107 compliant caching library). It might happen than more that one
|
||||
provider is present, in which case the provider must be explicitly specified. Even if the
|
||||
JSR-107 standard does not enforce a standardized way to define the location of the
|
||||
configuration file, Spring Boot does its best to accommodate with implementation details.
|
||||
|
||||
[source,properties,indent=0]
|
||||
----
|
||||
# Only necessary if more than one provider is present
|
||||
spring.cache.jcache.provider=com.acme.MyCachingProvider
|
||||
spring.cache.jcache.config=classpath:acme.xml
|
||||
----
|
||||
|
||||
NOTE: Since a cache library may offer both a native implementation and JSR-107 support
|
||||
it is advised to set the `spring.cache.type` to `jcache` to force that mode if that's
|
||||
what you want.
|
||||
|
||||
There are several ways to customize the underlying `javax.cache.cacheManager`:
|
||||
|
||||
* Caches can be created on startup via the `spring.cache.cache-names` property. If a custom
|
||||
`javax.cache.configuration.Configuration` bean is defined, it is used to customize them.
|
||||
* `org.springframework.boot.autoconfigure.cache.JCacheManagerCustomizer` beans are
|
||||
invoked with the reference of the `CacheManager` for full customization.
|
||||
|
||||
TIP: If a standard `javax.cache.CacheManager` bean is defined, it is wrapped
|
||||
automatically in a `org.springframework.cache.CacheManager` implementation that the
|
||||
abstraction expects. No further customization is applied on it.
|
||||
|
||||
|
||||
|
||||
[[boot-features-caching-provider-redis]]
|
||||
==== Redis
|
||||
If Redis is available and configured, the `RedisCacheManager` is auto-configured. It is
|
||||
|
||||
Reference in New Issue
Block a user