jedis 连接池错误

你离开我真会死。 提交于 2020-01-23 09:41:26

  The constructor JedisPool(GenericObjectPoolConfig, String, int) refers to the missing type GenericObjectPoolConfig

  并且JedisPoolConfig创建的对象 没有setMaxTotal,setMaxIdle 等方法.

  查看JedisPoolConfig

GenericObjectPoolConfig 这个类没有找到

原因:

commons-pool.jar 错误,因为GenericObjectPoolConfig 这个方法只有在commons-pool2.jar中才有。

commons-pool2.jar的下载地址:

http://commons.apache.org/proper/commons-pool/download_pool.cgi

代码如下

public void demo2() {
        JedisPool jedisPool =null;
        Jedis jedis=null;
        try {
            JedisPoolConfig config=new JedisPoolConfig();
            config.setMaxTotal(200);
            config.setMaxIdle(100);
            config.setMaxWaitMillis(100*60);
            jedisPool=new JedisPool(config,"127.0.0.1",6379);
            jedis=jedisPool.getResource();
            jedis.set("login-name", "张三");
            String loginNameString= jedis.get("login-name");
            System.out.println(loginNameString);
        } catch (Exception e) {
            // TODO: handle exception
        }finally{
            if(jedis!=null){
                jedis.close();
            }
            if(jedisPool!=null){
                jedisPool.close();
            }
        }
    }

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!