本篇介绍了SpringBoot 缓存(EhCache 2.x 篇),分享给大家,具体如下:
SpringBoot 缓存
在 spring Boot中,通过@EnableCaching注解自动化配置合适的缓存管理器(CacheManager),Spring Boot根据下面的顺序去侦测缓存提供者:
- Generic
- JCache (JSR-107)
- EhCache 2.x
- Hazelcast
- Infinispan
- Redis
- Guava
- Simple
关于 Spring Boot 的缓存机制:
高速缓存抽象不提供实际存储,并且依赖于由org.springframework.cache.Cache和org.springframework.cache.CacheManager接口实现的抽象。 Spring Boot根据实现自动配置合适的CacheManager,只要缓存支持通过@EnableCaching注释启用即可。
Spring Boot 配置 EhCache 2.x
官方文档上对于注解缓存的介绍资料非常之少,往往需要我们自己去了解相应的缓存提供者。我这里主要介绍的是 EhCache .
引入依赖
在pom.xml文件中引入以下依赖
<!--开启 cache 缓存--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-cache</artifactId> </dependency> <!-- ehcache 缓存 --> <dependency> <groupId>net.sf.ehcache</groupId> <artifactId>ehcache</artifactId> </dependency>引入配置文件 ehcache.xml
在resource文件夹下创建文件ehcache.xml,并进行配置:
<?xml version="1.0" encoding="UTF-8"?><ehcache xmlns:xsi="http:///FunriLy/springboot-study/tree/master/%E6%A1%88%E4%BE%8B9以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。