1.在maven中加入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
2.在application.yml中加入
spring:
redis:
database: 2
host: 101.201.70.209
port: 6379
pool:
max-active: 8
max-idle: 0
max-wait: -1
min-idle: 0
3.在启动类加入@EnableCaching
启用缓存
4.在需要缓存的方法上加 @Cacheable(value = "key")