> For the complete documentation index, see [llms.txt](https://jack80342.gitbook.io/spring-boot/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jack80342.gitbook.io/spring-boot/iv.-spring-boot-features/31.-caching/31.1-supported-cache-providers/31.1.2-jcache-jsr-107.md).

# 31.1.2 JCache (JSR-107)

类路径下存在`javax.cache.spi.CachingProvider`（也就是，类路径下存在一个遵循JSR-107的缓存库），并且`spring-boot-starter-cache`“Starter”提供了`JCacheCacheManager`，则[JCache](https://jcp.org/en/jsr/detail?id=107)将启动。这里有很多遵循JSR-107的库，Spring Boot为Ehcache 3、Hazelcast和Infinispan提供依赖管理。也可以添加其他库。

如果出现多个提供商，你需要明确指定使用哪个（提供商）。尽管JSR-107标准没有强制定义配置文件的位置，Spring Boot会尽量配合各实现情况：

```
# Only necessary if more than one provider is present
spring.cache.jcache.provider=com.acme.MyCachingProvider
spring.cache.jcache.config=classpath:acme.xml
```

**注** 由于一个缓存library可能提供的既有native实现，也有JSR-107支持，Spring Boot将优先使用JSR-107支持，这样如果你切换到不同的JSR-107实现，相同特性依旧可以使用。

**提示** Spring Boot对Hazelcast有[广泛支持](https://github.com/jack80342/Spring-Boot-Reference-Guide/tree/e85c52ad90d471a2b1f2ab65524e6183b50e9e74/IV.%20Spring%20Boot%20features/38.%20Hazelcast.md)。如果单个的`HazelcastInstance`可用，它就会被`CacheManager`重复使用，除非指定了`spring.cache.jcache.config`属性。

以下方式可以自定义底层的`javax.cache.cacheManager`：

* 通过设置`spring.cache.cache-names`属性，缓存可以在启动时就被创建。如果定义一个`javax.cache.configuration.Configuration` bean，它将用于自定义缓存。
* 使用`CacheManager`的引用调用`org.springframework.boot.autoconfigure.cache.JCacheManagerCustomizer` beans可完成全部配置。

**注** 如果定义标准的`javax.cache.CacheManager`，它将自动包装进`org.springframework.cache.CacheManager`以实现预期的抽象，也不能对它进一步配置了。
