Spring 整合redis集群 实现 以及过程中需要注意的问题点

一,准备工作:

1.首先安装好redis集群,启动并配置集群。

2.SpringMVC环境,看项目或个人需要,可以使SpringMVC的web项目,也可以是只使用SpringBean管理器。

二,着手配置:

由于项目是由maven管理的所以需要的jar 包添加到maven 的pom文件即可


1.添加jar依赖,再maven pom.xml 文件中添加依赖如下:// 这里需要说明下,依赖的jar包 redis.client  和 spring-data-redis 的版本匹配问题 实验了好几个对应如下

       redis.client  2.9.0 ---- spring-data-redis  1.7.1.RELEASE

       redis.client 2.9.0 -----spring-data-redis   1.7.2.RELEASE    这两个是可以使用的

       由于版本不匹配,遇到的错误如下:

         1. ClassNotFoundException  : redis/client/util/geoUtils    说这个类找不到。

         2. org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'redisTemplate' defined in class path resource [applicationContext.xml]

             说创建 redisTemplate bean 对象时失败了。

           <!-- jedis (一个redis client端的jar)-->

          <dependency>
            <groupId>redis.clients</groupId>
            <artifactId>jedis</artifactId>
            <version>2.9.0</version>
        </dependency>

         <!-- spring-data-redis 依赖-->

        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-redis</artifactId>
            <version>1.7.1.RELEASE</version>
        </dependency>

2.配置redis 配置文件 我把它单独提取出来放在一个配置文件(spring-data-redis-cluster.xml)中,然后import 到 spring ApplicationContext.xml 文件中:

spring-data-redis-cluster.xml 配置如下:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:task="http://www.springframework.org/schema/task" 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:/

  • 1
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 10
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值