引起:java.lang.BootstrapMethodError:java.lang.NoClassDefFoundError:redis/clients/jedis/Tuple - Redis S
Posted
技术标签:
【中文标题】引起:java.lang.BootstrapMethodError:java.lang.NoClassDefFoundError:redis/clients/jedis/Tuple - Redis Spring Boot【英文标题】:Caused by: java.lang.BootstrapMethodError: java.lang.NoClassDefFoundError: redis/clients/jedis/Tuple - Redis Spring Boot 【发布时间】:2018-12-22 05:59:53 【问题描述】:我正在使用 Spring Data Redis 示例。在此示例中,只是尝试连接到 redis 数据库。运行 main 方法,出现以下错误。
Spring Boot 使用的版本是 v 2.0.3.RELEASE & Redis 版本 是 2.4.5。
代码参考取自:http://javasampleapproach.com/spring-framework/spring-data/spring-data-redis-example-spring-boot-redis-example 和 https://docs.spring.io/spring-session/docs/current/reference/html5/guides/boot-redis.html。有人可以建议这里有什么问题吗?
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;
依赖树:
[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
【问题讨论】:
你确定你在类路径中有这个依赖 spring-boot-starter-data-redis 吗? @Maxim - 添加了 maven 依赖树。 【参考方案1】:您的示例引用了使用Jedis
的引导1.5.X
,默认情况下lettuce
用于引导2.0
,如果要使用Jedis
,则需要手动添加依赖项。此外,您可以看到 Jedis
不在您的类路径中,而 lettuce
在。
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
</dependency>
您可能需要指定依赖版本。或者,您可以通过lettuce
配置您正在尝试的内容。
【讨论】:
你仍然可以使用 Jedis,它仍然支持使用。 baeldung.com/java-redis-lettuce 有基本配置的演练。以上是关于引起:java.lang.BootstrapMethodError:java.lang.NoClassDefFoundError:redis/clients/jedis/Tuple - Redis S的主要内容,如果未能解决你的问题,请参考以下文章
csharp 可能会引起问题的类的继承问题,父类后来增加的方法可能会引起子类的函数重载错误