Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Caused by: java.lang.BootstrapMethodError: java.lang.NoClassDefFoundError: redis/clients/jedis/Tuple - Redis Spring Boot

I am using Spring Data Redis example. In this example, simply trying to connect to the redis DB. Runnning the main method, I am getting below error.

Spring Boot version used is v 2.0.3.RELEASE & Redis version is 2.4.5.

Code reference taken from : http://javasampleapproach.com/spring-framework/spring-data/spring-data-redis-example-spring-boot-redis-example and https://docs.spring.io/spring-session/docs/current/reference/html5/guides/boot-redis.html. Can anybody please suggest what is wrong here ?

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jedisConnectionFactory' defined in class path resource [com/javasampleapproach/redis/config/RedisConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.redis.connection.jedis.JedisConnectionFactory]: Factory method 'jedisConnectionFactory' threw exception; nested exception is java.lang.BootstrapMethodError: java.lang.NoClassDefFoundError: redis/clients/jedis/Tuple
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:590) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1256) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1105) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:503) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:251) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.addCandidateEntry(DefaultListableBeanFactory.java:1325) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1291) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveMultipleBeans(DefaultListableBeanFactory.java:1218) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1096) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1065) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:818) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:724) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    ... 82 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.redis.connection.jedis.JedisConnectionFactory]: Factory method 'jedisConnectionFactory' threw exception; nested exception is java.lang.BootstrapMethodError: java.lang.NoClassDefFoundError: redis/clients/jedis/Tuple
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:582) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    ... 98 common frames omitted
Caused by: java.lang.BootstrapMethodError: java.lang.NoClassDefFoundError: redis/clients/jedis/Tuple
    at org.springframework.data.redis.connection.jedis.JedisConverters.<clinit>(JedisConverters.java:124) ~[spring-data-redis-2.0.8.RELEASE.jar:2.0.8.RELEASE]
    at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.<clinit>(JedisConnectionFactory.java:92) ~[spring-data-redis-2.0.8.RELEASE.jar:2.0.8.RELEASE]
    at com.javasampleapproach.redis.config.RedisConfig.jedisConnectionFactory(RedisConfig.java:16) ~[classes/:na]
    at com.javasampleapproach.redis.config.RedisConfig$$EnhancerBySpringCGLIB$$8b8821c.CGLIB$jedisConnectionFactory$1(<generated>) ~[classes/:na]
    at com.javasampleapproach.redis.config.RedisConfig$$EnhancerBySpringCGLIB$$8b8821c$$FastClassBySpringCGLIB$$8d807fb2.invoke(<generated>) ~[classes/:na]
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:361) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at com.javasampleapproach.redis.config.RedisConfig$$EnhancerBySpringCGLIB$$8b8821c.jedisConnectionFactory(<generated>) ~[classes/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_151]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_151]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_151]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_151]
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    ... 99 common frames omitted
Caused by: java.lang.NoClassDefFoundError: redis/clients/jedis/Tuple
    ... 112 common frames omitted
Caused by: java.lang.ClassNotFoundException: redis.clients.jedis.Tuple
    at java.net.URLClassLoader.findClass(Unknown Source) ~[na:1.8.0_151]
    at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0_151]
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) ~[na:1.8.0_151]
    at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0_151]
    ... 112 common frames omitted

application.properties

# Session store type.
spring.session.store-type=redis
spring.session.redis.flush-mode=on-save
spring.session.redis.namespace=spring:session

#Configuring the Redis Connection
# Redis server host.
spring.redis.host=localhost 

# Login password of the redis server.
spring.redis.password= 

# Redis server port.
spring.redis.port=6379 

Customer.java

@Data
@Builder
public class Customer implements Serializable{
    private static final long serialVersionUID = 1L;

    private long id;
    private String firstName;
    private String lastName;
}

RedisConfig.java

@Configuration
@ComponentScan("com.javasampleapproach.redis")
public class RedisConfig {

    @Bean
    public JedisConnectionFactory jedisConnectionFactory() {
        return new JedisConnectionFactory();
    }

    @Bean
    public RedisTemplate<String, Object> redisTemplate(){
        final RedisTemplate<String, Object> template = new RedisTemplate<>();
        template.setConnectionFactory(jedisConnectionFactory());
        template.setValueSerializer(new GenericToStringSerializer<Object>(Object.class));
        return template;
    }
}

dependency tree:

[INFO] com.javasampleapproach:spring-data-redis:jar:1.0
[INFO] +- org.springframework.boot:spring-boot-starter-actuator:jar:2.0.3.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter:jar:2.0.3.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot:jar:2.0.3.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-autoconfigure:jar:2.0.3.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-starter-logging:jar:2.0.3.RELEASE:compile
[INFO] |  |  |  +- ch.qos.logback:logback-classic:jar:1.2.3:compile
[INFO] |  |  |  |  \- ch.qos.logback:logback-core:jar:1.2.3:compile
[INFO] |  |  |  +- org.apache.logging.log4j:log4j-to-slf4j:jar:2.10.0:compile
[INFO] |  |  |  |  \- org.apache.logging.log4j:log4j-api:jar:2.10.0:compile
[INFO] |  |  |  \- org.slf4j:jul-to-slf4j:jar:1.7.25:compile
[INFO] |  |  +- javax.annotation:javax.annotation-api:jar:1.3.2:compile
[INFO] |  |  \- org.yaml:snakeyaml:jar:1.19:runtime
[INFO] |  +- org.springframework.boot:spring-boot-actuator-autoconfigure:jar:2.0.3.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-actuator:jar:2.0.3.RELEASE:compile
[INFO] |  |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.9.6:compile
[INFO] |  |  |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.9.0:compile
[INFO] |  |  |  \- com.fasterxml.jackson.core:jackson-core:jar:2.9.6:compile
[INFO] |  |  +- org.springframework:spring-context:jar:5.0.7.RELEASE:compile
[INFO] |  |  \- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.9.6:compile
[INFO] |  \- io.micrometer:micrometer-core:jar:1.0.5:compile
[INFO] |     +- org.hdrhistogram:HdrHistogram:jar:2.1.10:compile
[INFO] |     \- org.latencyutils:LatencyUtils:jar:2.0.3:compile
[INFO] +- org.springframework.boot:spring-boot-starter-data-redis:jar:2.0.3.RELEASE:compile
[INFO] |  +- org.springframework.data:spring-data-redis:jar:2.0.8.RELEASE:compile
[INFO] |  |  +- org.springframework.data:spring-data-keyvalue:jar:2.0.8.RELEASE:compile
[INFO] |  |  |  \- org.springframework.data:spring-data-commons:jar:2.0.8.RELEASE:compile
[INFO] |  |  +- org.springframework:spring-tx:jar:5.0.7.RELEASE:compile
[INFO] |  |  +- org.springframework:spring-oxm:jar:5.0.7.RELEASE:compile
[INFO] |  |  +- org.springframework:spring-aop:jar:5.0.7.RELEASE:compile
[INFO] |  |  +- org.springframework:spring-context-support:jar:5.0.7.RELEASE:compile
[INFO] |  |  \- org.slf4j:slf4j-api:jar:1.7.25:compile
[INFO] |  \- io.lettuce:lettuce-core:jar:5.0.4.RELEASE:compile
[INFO] |     +- io.projectreactor:reactor-core:jar:3.1.8.RELEASE:compile
[INFO] |     |  \- org.reactivestreams:reactive-streams:jar:1.0.2:compile
[INFO] |     +- io.netty:netty-common:jar:4.1.25.Final:compile
[INFO] |     +- io.netty:netty-transport:jar:4.1.25.Final:compile
[INFO] |     \- io.netty:netty-handler:jar:4.1.25.Final:compile
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:2.0.3.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-json:jar:2.0.3.RELEASE:compile
[INFO] |  |  +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.9.6:compile
[INFO] |  |  \- com.fasterxml.jackson.module:jackson-module-parameter-names:jar:2.9.6:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-tomcat:jar:2.0.3.RELEASE:compile
[INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-core:jar:8.5.31:compile
[INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-el:jar:8.5.31:compile
[INFO] |  |  \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:8.5.31:compile
[INFO] |  +- org.hibernate.validator:hibernate-validator:jar:6.0.10.Final:compile
[INFO] |  +- org.springframework:spring-web:jar:5.0.7.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-beans:jar:5.0.7.RELEASE:compile
[INFO] |  \- org.springframework:spring-webmvc:jar:5.0.7.RELEASE:compile
[INFO] |     \- org.springframework:spring-expression:jar:5.0.7.RELEASE:compile
[INFO] +- org.projectlombok:lombok:jar:1.16.22:compile (optional)
[INFO] \- org.springframework.boot:spring-boot-starter-test:jar:2.0.3.RELEASE:test
[INFO]    +- org.springframework.boot:spring-boot-test:jar:2.0.3.RELEASE:test
[INFO]    +- org.springframework.boot:spring-boot-test-autoconfigure:jar:2.0.3.RELEASE:test
[INFO]    +- com.jayway.jsonpath:json-path:jar:2.4.0:test
[INFO]    |  \- net.minidev:json-smart:jar:2.3:test
[INFO]    |     \- net.minidev:accessors-smart:jar:1.2:test
[INFO]    |        \- org.ow2.asm:asm:jar:5.0.4:test
[INFO]    +- junit:junit:jar:4.12:test
[INFO]    +- org.assertj:assertj-core:jar:3.9.1:test
[INFO]    +- org.mockito:mockito-core:jar:2.15.0:test
[INFO]    |  +- net.bytebuddy:byte-buddy:jar:1.7.11:test
[INFO]    |  +- net.bytebuddy:byte-buddy-agent:jar:1.7.11:test
[INFO]    |  \- org.objenesis:objenesis:jar:2.6:test
[INFO]    +- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO]    +- org.hamcrest:hamcrest-library:jar:1.3:test
[INFO]    +- org.skyscreamer:jsonassert:jar:1.5.0:test
[INFO]    |  \- com.vaadin.external.google:android-json:jar:0.0.20131108.vaadin1:test
[INFO]    +- org.springframework:spring-core:jar:5.0.7.RELEASE:compile
[INFO]    |  \- org.springframework:spring-jcl:jar:5.0.7.RELEASE:compile
[INFO]    +- org.springframework:spring-test:jar:5.0.7.RELEASE:test
[INFO]    \- org.xmlunit:xmlunit-core:jar:2.5.1:test
like image 289
Jeff Cook Avatar asked Jul 13 '18 20:07

Jeff Cook


1 Answers

Your example is referencing boot 1.5.X which uses Jedis, by default lettuce is used in Boot 2.0 if you want to use Jedis you need to manually add the dependency. Additionally you can see that Jedis isn't on your classpath and lettuce is.

<dependency>
    <groupId>redis.clients</groupId>
    <artifactId>jedis</artifactId>
</dependency>

You might need to specify the dependency version. Alternatively you could just configure what you are attempting via lettuce.

like image 88
Darren Forsythe Avatar answered Nov 15 '22 06:11

Darren Forsythe