没有合适的资源?快使用搜索试试~ 我知道了~
资源详情
资源评论
资源推荐
此文章已于 9:21:39 2017/12/11 发布到 HealerJean 梦想博客
spring redis 注解开发 单片机 集群 主从复制
类别 redis
失败记录 ,虽然最终没有成功,但是原理还
是知道的
1、spring reids 简单实现注解
http://blog.csdn.net/fighterandknight/article/details/53432276/
1、导入相应依赖
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.8.1</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-
redis</artifactId>
<version>1.7.2.RELEASE</version>
</dependency>
2、redis 配置信息 properties
redis.host=127.0.0.1
redis.port=6379
redis.password=
redis.maxIdle=100
redis.maxActive=300
redis.maxWait=1000
redis.testOnBorrow=true
redis.timeout=10000
3、spring redis 配置文件
1、poolConfig ,导入 reids 信息,注意新旧版本参数名字不一样
哦
2、JedisConnectionFactory,redis 连接工厂,将
poolConfig 导入,并配置 host,port,ip password 等
3、redis 处理类 JedisTemplate,将连接工厂导入进来,
(spring boot 中用来处理 key 的序列化)
4、缓存管理器,配置 cache(这个时候,需要自己写
一个 RedisCach 类,将 JedisTemplate 导入,并设置缓
存位置名称 name,(这里就是相当于 Ehcache 管理管
理工厂)这个时候还可以配置多个 redis 缓存名称)
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:cache="http://www.springframework.org/schema/cache"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
http://www.springframework.org/schema/cache
http://www.springframework.org/schema/cache/spring-cache-4.2.xsd">
<context:property-placeholder location="classpath:redis-
config.properties" />
<!-- 启用缓存注解功能,这个是必须的,否则注解不会生效,另外,该注解一
定要声明在spring主配置文件中才会生效 -->
<cache:annotation-driven cache-manager="cacheManager" />
<!-- redis 相关配置 -->
<bean id="poolConfig"
class="redis.clients.jedis.JedisPoolConfig">
<property name="maxIdle" value="${redis.maxIdle}" />
<property name="maxWaitMillis" value="${redis.maxWait}" />
<property name="testOnBorrow" value="${redis.testOnBorrow}"
/>
</bean>
<bean id="JedisConnectionFactory"
class="org.springframework.data.redis.connection.jedis.JedisConnecti
onFactory"
p:host-name="${redis.host}"
p:port="${redis.port}"
p:password="${redis.pass}"
p:pool-config-ref="poolConfig"/>
<bean id="redisTemplate"
class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory"
ref="JedisConnectionFactory" />
</bean>
<!-- spring自己的缓存管理器,这里定义了缓存位置名称 ,即注解中的
value 名称和Ehcache有点像,是吧,哈哈-->
<bean id="cacheManager"
class="org.springframework.cache.support.SimpleCacheManager">
<property name="caches">
<set>
<!-- 这里可以配置多个redis -->
<bean class="com.cn.util.RedisCache">
<property name="redisTemplate"
ref="redisTemplate" />
<property name="name" value="default"/>
</bean>
<bean class="com.cn.util.RedisCache">
<property name="redisTemplate"
ref="redisTemplate" />
<property name="name" value="common"/>
<!-- common名称要在类或方法的注解中使用 -->
</bean>
</set>
</property>
</bean>
</beans>
4、RedisCache 为使用注解开发,缓存类
public class RedisCache implements Cache{
private RedisTemplate<String, Object> redisTemplate;
private String name;
public RedisTemplate<String, Object> getRedisTemplate() {
return redisTemplate;
}
public void setRedisTemplate(RedisTemplate<String, Object>
redisTemplate) {
this.redisTemplate = redisTemplate;
}
public void setName(String name) {
剩余17页未读,继续阅读
邢小鹏
- 粉丝: 23
- 资源: 327
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- JavaScript《基于自动分析数据并给出营业建议的餐厅管理系统(接入AI) 》+源代码+项目说明及资料
- 355670834783295707ad04e-427f-4cde-9589-e578224a8459.zip
- 动态sql解析引擎,类似mybatis动态sql的功能
- EDA365-Skill-V2.5安装包,支持Allegro17.x版本
- C# 常用单词汇总,常用单词汇总
- 【ERP标准流程-标准流程-库内业务管理】(DOC 14页).doc
- Python《数据库期末作业-餐厅点单系统 》+源代码+设计资料
- 学生成绩管理系统(C++课程设计
- 双指针法判断链表有环-go语言实现
- MyBatis动态SQL是一种强大的特性,它允许我们在SQL语句中根据条件动态地添加或删除某些部分,从而实现更加灵活和高效的数据
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0