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整合实例的更多相关文章

  1. Redis和Spring整合

    Redis和Spring整合 Redis在这篇里就不做介绍了~以后系统的学学,然后整理写出来. 首先是环境的搭建 通过自己引包的方式,将redis和spring-redis的包引到自己的项目中,我项目 ...

  2. 分布式缓存技术redis学习系列(五)——redis实战(redis与spring整合,分布式锁实现)

    本文是redis学习系列的第五篇,点击下面链接可回看系列文章 <redis简介以及linux上的安装> <详细讲解redis数据结构(内存模型)以及常用命令> <redi ...

  3. 分布式缓存技术redis系列(五)——redis实战(redis与spring整合,分布式锁实现)

    本文是redis学习系列的第五篇,点击下面链接可回看系列文章 <redis简介以及linux上的安装> <详细讲解redis数据结构(内存模型)以及常用命令> <redi ...

  4. redis系列之5----redis实战(redis与spring整合,分布式锁实现)

    本文是redis学习系列的第五篇,点击下面链接可回看系列文章 <redis简介以及linux上的安装> <详细讲解redis数据结构(内存模型)以及常用命令> <redi ...

  5. Redis跟Spring整合,sentinel模式

    普通模式整合 一.在pom.xml中引入redis的依赖 <dependency> <groupId>org.springframework.data</groupId& ...

  6. redis 与 spring整合 hash 增删改操作 list增删改操作

    本人,对于以前redis的学习是非常痛苦的!近期将以前的东西捡起来.以博客的形式存储,以便于以后快速捡起来,并和广大同胞一起分享! 1):简单介绍 redis 是基于C语言开发. redis是一个ke ...

  7. Redis + Jedis + Spring整合遇到的异常(转)

    项目中需要用到缓存,经过比较后,选择了redis,客户端使用jedis连接,也使用到了spring提供的spring-data-redis.配置正确后启动tomcat,发现如下异常: Caused b ...

  8. redis和spring整合使用

    第一步,在项目中加入redis的pom代码: <dependency> <groupId>redis.clients</groupId> <artifactI ...

  9. redis与spring整合·

    单机版: 配置spring配置文件applicationContext.xml <?xml version="1.0" encoding="UTF-8"? ...

随机推荐

  1. 关于db2中listagg函数开发中的体验

    一.首先解释一下可能会查询的基础问题: 1.1db2 “with ur”是什么意思: 在DB2中,共有四种隔离级:RS,RR,CS,UR.以下对四种隔离级进行一些描述,同时附上个人做试验的结果.隔离级 ...

  2. 《Mysql 一条 SQL 更新语句是如何执行的?(Redo log)》

    一:更新流程 - 对于更新来说,也同样会根据 SQL 的执行流程进行. -  - 连接器 - 连接数据库,具体的不做赘述. - 查询缓存 - 在一个表上有更新的时候,跟这个表有关的查询缓存会失效. - ...

  3. 顺序表添加与删除元素以及 php实现顺序表实例

    对顺序表的操作,添加与删除元素. 增加元素 如下图所示  对顺序列表 Li [1328,693,2529,254]  添加一个元素 111 ,有三种方式: a)尾部端插入元素,时间复杂度O(1);  ...

  4. spring cloud中代理服务器zuul的使用

    spring cloud中代理服务器zuul的使用 主流网关:     zuul     kong 基于nginx的API Gateway     nginx+lua 1.新建项目,选择eureka ...

  5. 1231: 删除字符串中指定的字符(Java)

    WUSTOJ 1231: 删除字符串中指定的字符 题目 原题链接 Description 明天就要英语考试了,小明明正在挑灯夜战背单词.小明明发现单词很难背,背一个忘一个.经过仔细研究,小明明发现单词 ...

  6. Nginx学习笔记(三):Nginx 请求处理

    Request Nginx 中的 ngx_http_request_t 是对一个 http 请求的封装: 一个 http 请求包含:请求行.请求头.请求体,响应行.响应头.响应体 Nginx 处理请求 ...

  7. PHP对程序员的要求更高

     我这个文章标题可不是和大家开玩笑的哦  首先, 大家都知道, PHP也是一种编译型脚本语言, 和其他的预编译型语言不同, 它不是编译成中间代码, 然后发布.. 而是每次运行都需要编译.. 为此, 也 ...

  8. hdu 3342 拓扑模板题

    直接上代码吧 #include<cstdio> #include<cstring> #include<algorithm> using namespace std; ...

  9. SQL 删除重复记录,并保留其中一条

    --查找表中多余的重复记录select * from code_xz where code in (select code from code_xz group by code having coun ...

  10. (十三)SpringBoot之Spring-Data-Jpa(二)CRUD实现以及添加自定义方法

    一.jpa中添加自定义方法 http://blog.csdn.net/qq_23660243/article/details/43194465 二.案例 1.3 引入jpa依赖 <depende ...