Hello when trying to use spring-redis i am getting
java.lang.NoClassDefFoundError: Could not initialize class org.springframework.data.redis.connection.jedis.JedisConnection
exception when doing any connection operation using redis. My config method goes like this
@Bean
public RedisConnectionFactory jedisConnFactory() {
JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory();
jedisConnectionFactory.setHostName("XXX.XX.XX.XXX");
jedisConnectionFactory.setPort(6381);
jedisConnectionFactory.setUsePool(true);
jedisConnectionFactory.afterPropertiesSet();
return jedisConnectionFactory;
Please suggest if anyone knows why i am getting this exception.
After wasting almost one day and finding that the jar is already on my class path, i further debugged it and found that when java's reflection mechanism was trying to find a method which was already present in the "methods list" it was not able to find due to some version conflict between Jedis version (2.7.2) not compatible with Spring Data Redis (1.5.0.RELEASE) , this issue has already been answered in this link ::
Jedis and spring data redis version conflict
latest version that Redis client still keeps old package structure is: 2.10.2.
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.10.2</version>
</dependency>
From 3.0.x, package structure has been changed. if spring-data-redis invokes Pool class of redis client with old package structure, then java.lang.NoClassDefFoundError
seems latest spring-data-redis: 2.1.10.RELEASE still invokes Pool class of redis client with old package structure so you need to use redis.clients 2.10.2
JedisPoolConfig is needed when we use Jedis Configuration. In Spring Boot 2.0, spring-boot-starter-data-redis gives Lettuce dependency by default instead of Jedis. To use Jedis configuration, exclude Lettuce and add Jedis as following.
<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>
</dependency>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With