public class JedisUtil { private static JedisPoolConfig config = new JedisPoolConfig(); private static JedisPool pool= new JedisPool(); static { //加载配置文件 InputStream is = JedisUtil.class.getClassLoader().getResourceAsStream("jedis.properties"); Properties pro = new Properties(); try { pro.load(is); } catch (IOException e) { e.printStackTrace(); } //初始化配置文件 config.setMaxIdle(Integer.parseInt(pro.getProperty("maxIdle"))); config.setMaxTotal(Integer.parseInt(pro.getProperty("maxTotal"))); //初始化Jedis连接池 pool=new JedisPool(config,pro.getProperty("host"),Integer.parseInt(pro.getProperty("port"))); } public static Jedis getJedis() { return pool.getResource(); } public static void close(JedisPool jedisPool){ jedisPool.close(); } }