事前准备

1、下载redis

https://github.com/MicrosoftArchive/redis/releases/tag/win-3.2.100

2、下载redis可视化工具

https://redisdesktop.com/download

3、启动redis

cd %redis%

redis-server.exe

配置

4、pom.xml追加

spring-data-redis

jedis

5、新建redis/redis.properties

redis.hostname=localhost
redis.port=6379
#redis.password=

6、新建springframework/spring-redis.xml

<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd"> <context:property-placeholder location="classpath:redis/redis.properties"
ignore-unresolvable="true" /> <bean id="redisConnectionFactory"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
<property name="hostName" value="${redis.hostname}" />
<property name="port" value="${redis.port}" />
</bean> <bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
<property name="ConnectionFactory" ref="redisConnectionFactory" />
</bean> <bean id="cacheManager"
class="org.springframework.data.redis.cache.RedisCacheManager">
<constructor-arg ref="redisTemplate" />
<property name="defaultExpiration" value="3000" />
</bean> </beans>

8、确保spring-redis.xml能被引入application-context.xml中

<import resource="classpath:springframework/spring-*.xml" />

7、至此,可以通过在ServiceImpl类的方法上追加@Cacheable @CachePut @CacheEvict 来实现缓存了。

最新文章

  1. Java 中如何原样输出转义符号
  2. ssh 无密码登陆
  3. HeadFirst 设计模式
  4. 汇总常用的jQuery操作Table tr td方法
  5. 【代码笔记】iOS-调用系统震动和声音
  6. 黄学长模拟day1 球的序列
  7. 纪念逝去的岁月——C/C++字符串旋转
  8. org.springframework.orm.hibernate3.LocalSessionFactoryBean的疑惑解决办法
  9. 【题解】【区间】【二分查找】【Leetcode】Insert Interval &amp; Merge Intervals
  10. JQ对JSON的增删改
  11. linux驱动调试--段错误之oops信息分析
  12. Palindrome Numbers(LA2889)第n个回文数是?
  13. 学习SQL关联查询
  14. Problem J: 求个最大值
  15. python简单分布式demo
  16. 教你用Python创建瀑布图
  17. 第六篇-以隐式意图(Implicit Intent)呼叫系统服务
  18. 【WPF】图片按钮的单击与双击事件
  19. oracle闪回数据
  20. 【TCP/IP详解 卷一:协议】第十一章 UDP 用户数据报协议

热门文章

  1. C# 弹出层移动
  2. EfCore基本用法
  3. PG SQL funcation
  4. Http 和 Socket 之间的恩爱情仇
  5. Axios使用拦截器全局处理请求重试
  6. 【小知识点】js无需刷新在url地址添加参数
  7. java输出月的日历控制台
  8. FI-TCODE收集
  9. Qt定时器
  10. 四:MySQL系列之Python交互(四)