开发者社区> 问答> 正文

redis从2.1升级到2.5.1报错:java.lang.NoSuchMethodError

在项目中使用了jedis-2.1.0.jar,现在升级为jedis-2.5.1,在初始化资源池时,总是报如下错误。
private JedisPool pool = new JedisPool(config, host, port, timeout, null, dbIndex); //这句报错。

commons-pool2-2.2.jar、jedis-2.5.1 都引入项目中了。
·private static void initialPool()

{
    ResourceBundle rb = ResourceBundle.getBundle("init");
    // 数据库,默认为0,目前总共为16个库
    // 读取配置文件中的数据库,默认为0,目前总共为16个库
    int dbIndex = Integer.parseInt(rb.getString("redis.dbindex"));
    // 读取配置文件中的IP地址
    String host = rb.getString("redis.host");
    // 读取配置文件中的端口号
    int port = Integer.parseInt(rb.getString("redis.port"));
    // 读取配置文件中的超时时间
    int timeout = Integer.parseInt(rb.getString("redis.timeout"));
    // 最大分配的对象数
    int maxActive = Integer.parseInt(rb.getString("redis.maxActive"));
    // 最大空闲数,数据库连接的最大空闲时间。超过空闲时间,数据库连接将被标记为不可用,然后被释放。设为0表示无限制
    int maxIdle = Integer.parseInt(rb.getString("redis.maxIdle"));
    // 当池内没有返回对象时,最大等待时间
    int maxWait = Integer.parseInt(rb.getString("redis.maxWait"));
    // 当调用borrow Object方法时,是否进行有效性检查
    String testOnBorrow = rb.getString("redis.testOnBorrow");
    boolean onBorrow = false;
    if (testOnBorrow.equals("true"))
    {
        onBorrow = true;
    }  
  org.apache.commons.pool2.impl.GenericObjectPoolConfig  config = new org.apache.commons.pool2.impl.GenericObjectPoolConfig ();
  //连接耗尽时是否阻塞, false报异常,ture阻塞直到超时, 默认true
  config.setBlockWhenExhausted(true);
  //设置的逐出策略类名, 默认DefaultEvictionPolicy(当连接超过最大空闲时间,或连接数超过最大空闲连接数)
  config.setEvictionPolicyClassName("org.apache.commons.pool2.impl.DefaultEvictionPolicy");   
  //是否启用pool的jmx管理功能, 默认true
  config.setJmxEnabled(true);
  //MBean ObjectName = new ObjectName("org.apache.commons.pool2:type=GenericObjectPool,name=" + "pool" + i); 默认为"pool", JMX不熟,具体不知道是干啥的...默认就好.
  config.setJmxNamePrefix("pool");
  //是否启用后进先出, 默认true
  config.setLifo(true);
  //最大空闲连接数, 默认8个
  config.setMaxIdle(maxIdle);
  //最大连接数, 默认8个
  config.setMaxTotal(maxActive);
  //获取连接时的最大等待毫秒数(如果设置为阻塞时BlockWhenExhausted),如果超时就抛异常, 小于零:阻塞不确定的时间,  默认-1
  config.setMaxWaitMillis(maxWait);
   
  //逐出连接的最小空闲时间 默认1800000毫秒(30分钟)
  config.setMinEvictableIdleTimeMillis(1800000);
   
  //最小空闲连接数, 默认0
  config.setMinIdle(0);
   
  //每次逐出检查时 逐出的最大数目 如果为负数就是 : 1/abs(n), 默认3
  config.setNumTestsPerEvictionRun(3);
   
  //对象空闲多久后逐出, 当空闲时间>该值 且 空闲连接>最大空闲数 时直接逐出,不再根据MinEvictableIdleTimeMillis判断  (默认逐出策略)   
  config.setSoftMinEvictableIdleTimeMillis(1800000);
   
  //在获取连接的时候检查有效性, 默认false
  config.setTestOnBorrow(false);
   
  //在空闲时检查有效性, 默认false
  config.setTestWhileIdle(false);
   
  //逐出扫描的时间间隔(毫秒) 如果为负数,则不运行逐出线程, 默认-1
  config.setTimeBetweenEvictionRunsMillis(-1);
   
  private JedisPool pool = new JedisPool(config, host, port, timeout, null, dbIndex);
}·

·Caused by: java.lang.NoSuchMethodError: redis.clients.jedis.JedisPool.(Lorg/apache/commons/pool2/impl/GenericObjectPoolConfig;Ljava/lang/String;IILjava/lang/String;I)V
at com.zk.common.util.Redis.initialPool(Redis.java:126)
at com.zk.common.util.Redis.getJedis(Redis.java:162)
at com.zk.common.util.Redis.lrange(Redis.java:813)
at com.zk.adms.router.AdmsDataRouter.polling(AdmsDataRouter.java:192)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.util.MethodInvoker.invoke(MethodInvoker.java:273)
at org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean$MethodInvokingJob.executeInternal(MethodInvokingJobDetailFactoryBean.java:264)
... 3 more·

展开
收起
蛮大人123 2016-02-05 11:09:39 8162 0
1 条回答
写回答
取消 提交回答
  • 我说我不帅他们就打我,还说我虚伪

    jedis-2.1.0.jar,现在升级为jedis-2.5.1有些参数名字变了
    比如maxWait -》 maxWaitMillis
    一些方法名也变了,需要对应改一下。

    2019-07-17 18:37:40
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Spring Cloud Alibaba - 重新定义 Java Cloud-Native 立即下载
The Reactive Cloud Native Arch 立即下载
JAVA开发手册1.5.0 立即下载