pom.xml

  <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

application.properties

#缓存配置
spring.cache.cache-names=c1,c2
spring.cache.redis.time-to-live=1800s
#Redis配置
spring.redis.database=0
spring.redis.host=192.168.205.100
spring.redis.port=6379
spring.redis.password=123456
spring.redis.jedis.pool.max-active=8
spring.redis.jedis.pool.max-idle=8
spring.redis.jedis.pool.max-wait=-1ms
spring.redis.jedis.pool.min-idle=0

dao

@Repository
public class BookDao {
@Cacheable("c1")
public Book getBookById(Integer id) {
System.out.println("getBookById");
Book book = new Book();
book.setId(id);
book.setName("三国演义");
book.setAuthor("罗贯中");
return book;
}
}

项目入口类开启缓存:

@SpringBootApplication
@EnableCaching
public class RediscacheApplication {
public static void main(String[] args) {
SpringApplication.run(RediscacheApplication.class, args);
}
}

最新文章

  1. 在 CentOS7 上安装 MySQL5.7
  2. dell omsa 监控,Nrpe信号量泄露
  3. mysqli事务处理demo
  4. ZOJ-2365 Strong Defence 贪心,BFS
  5. GetWindowText
  6. WCF入门教程系列二
  7. git操作标签
  8. 在Ubuntu Desktop打开终端的2种方式
  9. PHP开发笔记
  10. wpf xmal基础
  11. 首届.NET Core开源峰会
  12. linux高级编程
  13. OpenCV常用头文件介绍
  14. 描点的改进:运用chart画图。
  15. mysql分区分表讲解
  16. 音频 PCM 数据的采集和播放
  17. auto类型-现代C++新特性
  18. Mysql 多个字段查找重复数
  19. VS调用python方法
  20. JAVA 读取txt文件内容

热门文章

  1. sqli_labs学习笔记(一)Less-54~Less-65
  2. qq机器人 python实现 自动回复
  3. apache 目录网站显示indexs
  4. JMeter入门 | 第一个并发测试
  5. Nginx 配置访问本地目录
  6. Spring注入bean的方式
  7. 视觉slam十四讲ch5 joinMap.cpp 代码注释(笔记版)
  8. CCF_ 201512-3_画图
  9. kendo ui - core
  10. 《C# 爬虫 破境之道》:第二境 爬虫应用 — 第六节:反爬策略研究