Я пытаюсь перейти с весенней загрузки 1.5.5 на весеннюю загрузку 2. Я получаю следующее для JedisPool
Parameter 0 of method getJedisPool in com.company.spring.config.ApplicationConfig required a bean of type 'org.springframework.data.redis.connection.jedis.JedisConnectionFactory' that could not be found.
- Bean method 'redisConnectionFactory' in 'JedisConnectionConfiguration' not loaded because @ConditionalOnMissingBean (types: org.springframework.data.redis.connection.RedisConnectionFactory; SearchStrategy: all) found beans of type 'org.springframework.data.redis.connection.RedisConnectionFactory' redisConnectionFactory
Я пытаюсь настроить, используя Jedis, а не салат. Я проигнорировал модуль салата при импорте данных spring-starter-redis-data, как это предлагается в документации.
Ниже приведен код, который пытается инициализировать JedisPool.
@Bean
public JedisPool getJedisPool(JedisConnectionFactory jedisConnectionFactory) {
String host = jedisConnectionFactory.getHostName();
int port = jedisConnectionFactory.getPort();
String password = StringUtils.isEmpty(jedisConnectionFactory.getPassword()) ? null : jedisConnectionFactory.getPassword();
int timeout = jedisConnectionFactory.getTimeout();
GenericObjectPoolConfig poolConfig = jedisConnectionFactory.getPoolConfig();
log.info("Starting Redis with Host:{}, Port:{}, Timeout:{}, PoolConfig:{}", host, port, timeout, poolConfig);
return new JedisPool(poolConfig, host, port, timeout, password);
}
Я исправил проблему, изменив bean-компонент на использование RedisProperties. Вот код, который в итоге заработал.
@Bean
public JedisPool getJedisPool(RedisProperties redisProperties) {
Pool jedisProperties = redisProperties.getJedis().getPool();
String password = StringUtils.isEmpty(redisProperties.getPassword()) ? null : redisProperties.getPassword();
int timeout = (int) redisProperties.getTimeout().toMillis();
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
poolConfig.setMaxIdle(jedisProperties.getMaxIdle());
poolConfig.setMaxTotal(jedisProperties.getMaxActive() + jedisProperties.getMaxIdle());
poolConfig.setMinIdle(jedisProperties.getMinIdle());
log.info("Starting Redis with Host:{}, Port:{}, Timeout(ms):{}, PoolConfig:{}", redisProperties.getHost(), redisProperties.getPort(),
timeout, poolConfig);
return new JedisPool(poolConfig, redisProperties.getHost(), redisProperties.getPort(), timeout, password);
}
Я не очень уверен, что это правильный способ настройки Jedis на SpringBoot 2.0. В любом случае это работает.
Спасибо, переходите с весенней загрузки 1.5.9 на весеннюю загрузку 2.