具體報(bào)錯信息如下:
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
出現(xiàn)錯誤的原因可能有以下幾點(diǎn):
- 查看Jedis配置redis的信息是否有誤,主要是ip,端口和密碼是否寫錯。
- 查看服務(wù)器防火墻是否關(guān)閉,查看指令:systemctl status firewall,如果出現(xiàn)
Active:active(running)則表示防火墻是處于開啟狀態(tài)的,需要關(guān)閉。 關(guān)閉指令:systemctl stop firewall。關(guān)閉后是Active: inactive (dead)。 - 修改redis配置文件redis.conf。找到bind 127.0.0.1,把它進(jìn)行注釋掉;找到protected-mode yes 把它改成no。
- 如果是使用spring-session需要依賴redis2.8.0以上版本,并且需要開啟:notify-keyspace-events gxE;同樣在redis.conf中修改。
上述若修改了redis.conf文件,則必須要重啟redis服務(wù)器。