1.redis的依赖:
<!-- redis -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!-- spring2.X集成redis所需common-pool2-->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
<version>2.6.0</version>
</dependency>
2.使用了@Cacheable:第一次会访问查看redis是否有缓存,没有的话会调用方法,有的话直接从缓存里面取,但是一定要加在方法上。
但在方法上加入了@Cacheable注解不生效?
另外需要在启动类上添加 @EnableCaching才可以生效,记住!!!