Skip to content

How to resolve JedisShardInfo or JedisPoolConfig not found exception with Spring Boot application?

Problem

When running a Spring Boot application that accesses a Redis server, you might encounter the following errors:

Terminal window
the class redis.clients.jedis.JedisPoolConfig not found

Or:

Terminal window
the class redis.clients.jedis.JedisShardInfo not found

Or:

Terminal window
java.lang.ClassNotFoundException: redis.clients.jedis.util.Pool

Environment

  • Spring Boot 2.x or 3.x
  • Redis 6.x or 7.x

Code

Project Dependencies

We use Maven for dependency management. Below is the pom.xml configuration:

pom.xml
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>17</java.version>
<start-class>Application</start-class>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>3.1.2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
</dependencies>

Redis Configuration Class

RedisConfiguration.java
@Configuration
@ConfigurationProperties(prefix = "spring.redis")
public class Redis1Property {
private String host;
private int port;
private int database;
// Getters and setters omitted
}

Spring Boot requires a connection factory and a Redis template:

RedisConfiguration.java
@Configuration
public class Redis1Configuration {
@Autowired
private Redis1Property redis1Property;
@Primary
@Bean(name = "redis1ConnectionFactory")
public RedisConnectionFactory redis1ConnectionFactory() {
RedisStandaloneConfiguration config = new RedisStandaloneConfiguration(
redis1Property.getHost(), redis1Property.getPort());
return new JedisConnectionFactory(config);
}
@Bean(name = "redis1StringRedisTemplate")
public StringRedisTemplate userStringRedisTemplate(@Qualifier("redis1ConnectionFactory") RedisConnectionFactory cf) {
StringRedisTemplate stringRedisTemplate = new StringRedisTemplate();
stringRedisTemplate.setConnectionFactory(cf);
return stringRedisTemplate;
}
}

Testing Redis Connection

MultiRedisTestRunner.java
@Component
public class MultiRedisTestRunner implements CommandLineRunner {
private final static Logger logger = LoggerFactory.getLogger(MultiRedisTestRunner.class);
@Autowired
@Qualifier("redis1StringRedisTemplate")
private StringRedisTemplate stringRedisTemplate;
public void run(String... strings) throws Exception {
CountDownLatch latch = new CountDownLatch(1);
try {
for (int i = 0; i < 1; i++) {
logger.info("Reading from Redis");
String key = "key" + i;
stringRedisTemplate.opsForValue().set(key, "value" + i);
String value = stringRedisTemplate.opsForValue().get(key);
logger.info(String.format("Key: %s, Value: %s", key, value));
}
} finally {
latch.await();
}
}
}

Reason

Solution

Modify your pom.xml to exclude Lettuce and explicitly include the correct Jedis version:

pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<exclusions>
<exclusion>
<groupId>io.lettuce</groupId>
<artifactId>lettuce-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>5.0.0</version>
</dependency>

After making this change, rerun your application, and the issue should be resolved.

Summary

The ‘JedisPoolConfig not found’ and ‘JedisShardInfo not found’ exceptions occur due to Spring Boot’s default usage of Lettuce instead of Jedis. If you want to use Jedis, you must explicitly exclude Lettuce and ensure you use a compatible Jedis version. Upgrading to jedis-5.0.0 resolves the dependency conflict.

Final Words + More Resources

My intention with this article was to help others who might be considering solving such a problem. So I hope that’s been the case here. If you still have any questions, don’t hesitate to ask me by email: Email me

Here are also the most important links from this article along with some further resources that will help you in this scope:

Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!