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

想学习学习redis缓存技术,于是到网上copy到了一些代码,粘贴到ecplise上面,但是发现代码总是报错

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

什么问题,我们不知道啊

想了半天发现是我引入了common-pool.jar这个包,但是没有buildpath,,也是醉了,

现在问题解决了

package com.wdg.util;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

public class RedisUtil {


    //Redis服务器IP
    private static String ADDR = "127.0.0.1";
    
    //Redis的端口号
    private static int PORT = 6379;
    
    //访问密码,若你的redis服务器没有设置密码,就不需要用密码去连接
    private static String AUTH = "123456";
    
    //可用连接实例的最大数目,默认值为8;
    private static int MAX_TOTAL = 512;
    
    //控制一个pool最多有多少个状态为idle(空闲的)的jedis实例,默认值也是8。
    private static int MAX_IDLE = 50;
    
    //等待可用连接的最大时间,单位毫秒,默认值为-1,表示永不超时。
    private static long MAX_WAIT = 10000;
    
    private static int TIMEOUT = 10000;
    
    //在borrow一个jedis实例时,是否提前进行validate操作;如果为true,则得到的jedis实例均是可用的;
    private static boolean TEST_ON_BORROW = true;
    
    private static JedisPool jedisPool = null;
    
    /**
     * 初始化Redis连接池
     */
    static {
        try {
            JedisPoolConfig config = new JedisPoolConfig();
            config.setMaxActive(MAX_TOTAL);
            config.setMaxIdle(MAX_IDLE);
            config.setMaxWait(MAX_WAIT);
   
            config.setTestOnBorrow(TEST_ON_BORROW);
         
            jedisPool=new JedisPool(config, ADDR, PORT);
          /*  jedisPool = new JedisPool(config, ADDR, PORT, TIMEOUT, AUTH);*/
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    /**
     * 获取Jedis实例
     * @return
     */
    public synchronized static Jedis getJedis() {
        try {
            if (jedisPool != null) {
                Jedis jedis = jedisPool.getResource();
                return jedis;
            } else {
                return null;
            }
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
    
    /**
     * 释放jedis资源
     * @param jedis
     */
    public static void returnResource(final Jedis jedis) {
        if (jedis != null) {
            jedisPool.returnResource(jedis);
        }
    }
}

引用了jar是:

commons-pool.jar

jedis-1.5.2.jar

如果大家想用着这两个jar可以到下面的地址去下载:

https://download.csdn.net/download/datouniao1/10313743

希望对你有所帮助


猜你喜欢

转载自blog.csdn.net/datouniao1/article/details/79729234