redis与spring整合实例
1)首先是redis的配置。
使用的是maven工程,引入redis与spring整合的相关jar包
<!-- redis服务 start-->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>1.6.2.RELEASE</version>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.6.2</version>
</dependency>
<!-- redis服务 end-->
2)在redis中增加相应配置文件:spring-redis.xml 内容
<?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:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
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">
<bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig">
<property name="maxIdle" value="${redis.maxIdle}" />
<property name="maxTotal" value="${redis.maxActive}" />
<property name="maxWaitMillis" value="${redis.maxWait}" />
<property name="testOnBorrow" value="${redis.testOnBorrow}" />
</bean>
<bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
<property name="poolConfig" ref="poolConfig" />
<property name="port" value="${redis.port}" />
<property name="hostName" value="${redis.host}" />
<property name="password" value="${redis.pass}" />
</bean>
<bean id="stringSerializer" class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
<bean id="jdkSerializationRedisSerializer" class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer"/>
<bean id="stringRedisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate">
<property name="connectionFactory" ref="jedisConnectionFactory" />
<property name="keySerializer" ref="stringSerializer" />
<property name="valueSerializer" ref="jdkSerializationRedisSerializer"/>
</bean>
<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="jedisConnectionFactory" />
<property name="keySerializer" ref="stringSerializer" />
<property name="valueSerializer" ref="jdkSerializationRedisSerializer"/>
</bean>
</beans>
3)在application中配置redis连接池需要的相关参数
#redis连接配置===================start=========================
# Redis settings
redis.host=192.168.10.102
redis.port=6379
redis.pass=
redis.maxIdle=1
redis.maxActive=9
redis.maxWait=1000
redis.testOnBorrow=true
#redis连接配置===================end=========================
4)在web.xml中引入相应的配置信息
<!-- ContextLoaderListener初始化Spring上下文时需要使用到的contextConfigLocation参数 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<!-- 配置spring.xml和spring-mybatis.xml这两个配置文件的位置,固定写法 -->
<param-value>
classpath:spring.xml,
classpath:spring-mybatis.xml,
classpath:spring-activitymq.xml,
classpath:dubbo.xml,
classpath:spring-redis.xml
</param-value>
</context-param>
5)启动tomcat服务,启动正常。

redis与spring整合实例的更多相关文章
- Redis和Spring整合
Redis和Spring整合 Redis在这篇里就不做介绍了~以后系统的学学,然后整理写出来. 首先是环境的搭建 通过自己引包的方式,将redis和spring-redis的包引到自己的项目中,我项目 ...
- 分布式缓存技术redis学习系列(五)——redis实战(redis与spring整合,分布式锁实现)
本文是redis学习系列的第五篇,点击下面链接可回看系列文章 <redis简介以及linux上的安装> <详细讲解redis数据结构(内存模型)以及常用命令> <redi ...
- 分布式缓存技术redis系列(五)——redis实战(redis与spring整合,分布式锁实现)
本文是redis学习系列的第五篇,点击下面链接可回看系列文章 <redis简介以及linux上的安装> <详细讲解redis数据结构(内存模型)以及常用命令> <redi ...
- redis系列之5----redis实战(redis与spring整合,分布式锁实现)
本文是redis学习系列的第五篇,点击下面链接可回看系列文章 <redis简介以及linux上的安装> <详细讲解redis数据结构(内存模型)以及常用命令> <redi ...
- Redis跟Spring整合,sentinel模式
普通模式整合 一.在pom.xml中引入redis的依赖 <dependency> <groupId>org.springframework.data</groupId& ...
- redis 与 spring整合 hash 增删改操作 list增删改操作
本人,对于以前redis的学习是非常痛苦的!近期将以前的东西捡起来.以博客的形式存储,以便于以后快速捡起来,并和广大同胞一起分享! 1):简单介绍 redis 是基于C语言开发. redis是一个ke ...
- Redis + Jedis + Spring整合遇到的异常(转)
项目中需要用到缓存,经过比较后,选择了redis,客户端使用jedis连接,也使用到了spring提供的spring-data-redis.配置正确后启动tomcat,发现如下异常: Caused b ...
- redis和spring整合使用
第一步,在项目中加入redis的pom代码: <dependency> <groupId>redis.clients</groupId> <artifactI ...
- redis与spring整合·
单机版: 配置spring配置文件applicationContext.xml <?xml version="1.0" encoding="UTF-8"? ...
随机推荐
- 数据结构 -- Trie字典树
简介 字典树:又称单词查找树,Trie树,是一种树形结构,是一种哈希树的变种. 优点:利用字符串的公共前缀来减少查询时间,最大限度地减少无谓的字符串比较,查询效率比哈希树高. 性质: 1. 根节 ...
- git 显示文件改动,但无具体改动信息
事件: 同步代码,进行了换行符替换 过程 : 同步代码,在正式服务器的 git 分支基础上创建新的分支,按照同步代码流程,将对方代码换行符转换(对方mac,我方windows) 替换需 ...
- phpstrom
在phpstrom 中启用composer 步骤: 1.打开编辑器,选择 文件(file)->设置(setting),找到 Command Line Tool Support ,点击 + 号进行 ...
- Scratch 母鸡保护鸡蛋
今天我们一起实现一个“母鸡保护鸡蛋”的小游戏 具体思路是这样滴: 1.鸡蛋会不断的从右往左移动: 2.当母鸡快碰到鸡蛋的时候,按下“空格键”让母鸡跳跃起来: 3.如果母鸡落下没碰到鸡蛋,加一分: 4. ...
- “Using 声明”在 C# 7.3 中不可用。请使用 8.0 或更高的语言版本。
Core3.0升级至3.1时候报错:“Using 声明”在 C# 7.3 中不可用.请使用 8.0 或更高的语言版本. 参照微软文档:https://docs.microsoft.com/zh-cn/ ...
- Luogu5363 SDOI2019移动金币(博弈+动态规划)
容易想到可以转化为一个有m堆石子,石子总数不超过n-m的阶梯博弈.阶梯博弈的结论是相当于只考虑奇数层石子的nim游戏. nim和不为0不好算,于是用总方案数减掉nim和为0的方案数.然后考虑dp,按位 ...
- Linux通用小技能
Linux通用小技能 前言 无论你用ubuntu还是centos,通通没问题,运维这东西,踩坑写文档就是了. 小技能 新磁盘挂载 不管是阿里云还是腾讯云,还是自己的机器,请记住这条命令. mkfs.e ...
- (七)Activiti之历史活动查询和历史任务查询和流程状态查询
一.历史活动查询 本章案例是基于上一章节案例的基础上,流程走完后进行测试的,也就是下图的流程从学生请假到班主任审批都已经完成,本章用来测试查询历史活动和历史任务的 activiti5的历史活动包括所有 ...
- Shell学习笔记:awk实现group by分组统计功能
日常部分数据以 txt 的文件格式提供,为避免入库之后再进行统计的麻烦,故学习 shell 进行处理,减少工作量. 1.样例数据 # test.txt YD5Gxxx|6618151|68254490 ...
- c# String常用方法