Spring启动:如果Jedis连接池不可用,请告诉服务器从数据库获取数据而不是抛出错误

时间:2017-07-13 11:47:58

标签: spring spring-boot redis spring-data-redis

有没有办法实现这个目标?

假设与redis的连接不可用,假设缓存不存在并直接从数据库中获取,而不是使整个应用程序失败

erc1 = cv2.text.loadClassifierNM1('./trained_classifierNM1.xml')
er1 = cv2.text.createERFilterNM1(erc1,16,0.00015,0.13,0.2,True,0.1)

erc2 = cv2.text.loadClassifierNM2('./trained_classifierNM2.xml')
er2 = cv2.text.createERFilterNM2(erc2,0.5) 

我在SO上关注这个答案: SO answer

但是我的spring boot仍会在启动时抛出异常并且它不会从数据库中获取数据:

@Cachable
public String cachingMethod(String cache) {
    return "cache";
}

我的配置代码是:

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
...
Caused by: redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
...
Caused by: redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: connect timed out
...
Caused by: java.net.SocketTimeoutException: connect timed out

0 个答案:

没有答案