使用Jedis连接redis出现Cannot get Jedis connection; Could not get a resource from the pool错误

具体报错信息如下:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'enableRedisKeyspaceNotificationsInitializer' defined in class path resource [org/springframework/session/data/redis/config/annotation/web/http/RedisHttpSessionConfiguration.class]: Invocation of init method failed; nested exception is org.springframework.data.redis.RedisConnectionFailureException: Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool

出现错误的原因可能有以下几点:

  1. 查看Jedis配置redis的信息是否有误,主要是ip,端口和密码是否写错。
  2. 查看服务器防火墙是否关闭,查看指令:systemctl status firewall,如果出现
    Active:active(running)则表示防火墙是处于开启状态的,需要关闭。 关闭指令:systemctl stop firewall。关闭后是Active: inactive (dead)。
  3. 修改redis配置文件redis.conf。找到bind 127.0.0.1,把它进行注释掉;找到protected-mode yes 把它改成no。
  4. 如果是使用spring-session需要依赖redis2.8.0以上版本,并且需要开启:notify-keyspace-events gxE;同样在redis.conf中修改。

上述若修改了redis.conf文件,则必须要重启redis服务器。

你可能感兴趣的:(使用Jedis连接redis出现Cannot get Jedis connection; Could not get a resource from the pool错误)