Spring Boot的cache支持多种缓存,其中常用的有EhCache和Redis,而Redis有专门的依赖,EhCache和Redis最大的不同是EhCache不依赖什么第三方软件,而redis还要启动Redis服务器,这里只将EhCache
如果不熟悉EhCache,请看这篇文章 ehcache入门基础示例
1. pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
</dependency>
2. application.properties
spring.cache.ehcache.config=classpath:config/ehcache.xml