spring+jedis配置问题

使用spring+Jedis配置

1.使用到的版本

spring3.1+redis2.4.5

jar包:

jedis-2.4.2.jar

spring-data-redis-1.4.2.RELEASE.jar

commons-pool2-2.4.2.jar

2.报错问题

2.1:Caused by: java.lang.NoSuchMethodError: redis.clients.jedis.JedisShardInfo.setTimeout(I)V

原因是之前用的jedis2.7.2.jar版本太高了,换成低版本jedis-2.4.2.jar。

2.2:Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'maxActive' of bean class [redis.clients.jedis.JedisPoolConfig]:

需要换成maxTotal

2.3:Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'maxWait' of bean class [redis.clients.jedis.JedisPoolConfig]

需要换成maxWaitMillis

之前的版本配置

 <bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig">  
        <property name="maxIdle" value="${redis.maxIdle}" />  
        <property name="maxActive" value="${redis.maxActive}" />  
        <property name="maxWait" value="${redis.maxWait}" />  
        <property name="testOnBorrow" value="${redis.testOnBorrow}" />  
    </bean>  

     maxActive 修改成 maxTotal, maxWait修改成maxWaitMillis.

<!-- jedis pool配置 -->
    <bean id="jedisPool" 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>     


<!-- spring data redis -->        
    <bean id="connectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
        <property name="usePool" value="true"></property>
        <property name="hostName" value="${redis.host}" />
        <property name="port" value="${redis.port}" />
        <property name="password" value="${redis.pass}" />
        <property name="timeout" value="${redis.timeout}" />
      <!--   <property name="database" value="${redis.default.db}"></property> -->
        <constructor-arg index="0" ref="jedisPool" />
    </bean>    
        
    <bean id="redisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate">  
        <property name="connectionFactory"   ref="connectionFactory" />  
    </bean>         
      
    <bean id="userDao" class="com.www.common.redis.UserDao" />

redis.properties

#redis的服务器地址
redis.host=10.13.17.33
#redis的服务端口
redis.port=6379
#密码
redis.pass=
#链接数据库
redis.default.db=0
#客户端超时时间单位是毫秒
redis.timeout=100000
#最大连接数
redis.maxActive=300
#最大空闲数
redis.maxIdle=100
#最大建立连接等待时间
redis.maxWait=1000
redis.testOnBorrow=true 
#指明是否在从池中取出连接前进行检验,如果检验失败,则从池中去除连接并尝试取出另一个
#DBSync.testOnBorrow=true


测试效果:



  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值