由于缓存是在单机使用的,因此根据文章https://www.cnblogs.com/qlqwjy/p/7788912.html的提示,使用的Ehcache,而不使用Redis作为缓存工具。
第一步,导入jar包。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
</dependency>
第二步,让SpringBoot知道你打算用缓存了,即增加EnableCaching注解。
@SpringBootApplication
@EnableCaching
public class ManualSpringbootApplication {
public static void main(String[] args) {
SpringApplication.run(ManualSpringbootApplication.class, args);
}
}
第三步,让spring知道你想用的是Ehcache缓存,而不是其他的缓存,在springboot的配置文件中增加缓存配置。
########