2
回答
JFinal Weixin 已经设置了RedisPlugin,获取值时提示Could not get a resource from the pool
滴滴云服务器,限时包月0.9元,为开发者而生>>>   


@JFinal 你好,
我在使用JFinal Weixin时,已经在代码中声明RedisPlugin,如下
public void configPlugin(Plugins me) {
// 配置C3p0数据库连接池插件
C3p0Plugin c3p0Plugin = new C3p0Plugin(PropKit.get("jdbcUrl"),
PropKit.get("user"), PropKit.get("password").trim());
me.add(c3p0Plugin);


//设置Redis缓存
RedisPlugin redis = new RedisPlugin("weixin", "localhost");
redis.start();
//me.add(redis);//添加该语句,会使cache对象为空
ApiConfigKit.setAccessTokenCache(new RedisAccessTokenCache());
}




实际使用中,在获取ACCESS_TOKEN时
public static AccessToken getAccessToken() {
String appId = ApiConfigKit.getApiConfig().getAppId();
AccessToken result = null;
try {
result = accessTokenCache.get(appId);
} finally {
if (result != null && result.isAvailable())
return result;

refreshAccessToken();
return accessTokenCache.get(appId);
}
}

accessTokenCache不为空,如图

但获取不到值,在refreshAccessToken方法中也写不了值,直接报错,提示“Could not get a resource from the pool?”?

redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
at redis.clients.util.Pool.getResource(Pool.java:50)
at redis.clients.jedis.JedisPool.getResource(JedisPool.java:86)
at com.jfinal.plugin.redis.Cache.getJedis(Cache.java:1202)
at com.jfinal.plugin.redis.Cache.setex(Cache.java:72)
at com.jfinal.weixin.sdk.cache.RedisAccessTokenCache.set(RedisAccessTokenCache.java:19)
at com.jfinal.weixin.sdk.api.AccessTokenApi.refreshAccessToken(AccessTokenApi.java:73)
at com.jfinal.weixin.sdk.api.AccessTokenApi.getAccessToken(AccessTokenApi.java:49)
at com.jfinal.weixin.sdk.api.JsTicketApi.getTicket(JsTicketApi.java:47)
请问是什么原因造成的,如何解决?谢谢。
举报
omguare
发帖于2年前 2回/1K+阅
顶部