JedisPoolUtils简单工具类的实现
static {
//读取配置文件
InputStream is = JedisPoolUtil.class.getClassLoader().getResourceAsStream("jedis.properties");
//创建properties对象
Properties pro = new Properties();
//关联文件
try {
pro.load(is);
} catch (IOException e) {
e.printStackTrace();
}
//获取连接池配置对象
JedisPoolConfig config = new JedisPoolConfig();
//从配置文件中找出数据设置配置对象
config.setMaxTotal(Integer.parseInt(pro.getProperty("maxTotal")));
config.setMaxTotal(Integer.parseInt(pro.getProperty("maxIdle")));
//初始化Jedispool
jedisPool = new JedisPool(config,pro.getProperty("host"),Integer.parseInt(pro.getProperty("port")));
}
public static Jedis getJedis(){
return jedisPool.getResource();
} 下面展示一些 `内联代码片`。
jedis.properties
```jedis.properties
host=127.0.0.1
port=6379
maxTotal=50
maxIdle=10
补充:报错情况java.lang.ExceptionInInitializerError
解决办法:在目录中src的子目录下创建一个resource 把配置文件jedis.properties丢进去就好了 我也不知道为什么 反正这么解决可以 如果知道为什么的告诉我一下 我郁闷死了