NoClassDefFoundError(GenericObjectPoolConfig|NoClassDefFoundError:GenericObjectPoolConfig 问题)
本文个人博客地址:https://www.leafage.top/posts/detail/21622MARQ
【NoClassDefFoundError(GenericObjectPoolConfig|NoClassDefFoundError:GenericObjectPoolConfig 问题)】记录一个redis的异常,今天更新测试环境的服务,该服务中使用了 spring-boot-starter-data-redis 的依赖,在发布测试的时候报错了,很尴尬。为啥呢,我本地运行的好好的呀。。。(是不是你的日常?)。
这个错的具体信息如下:
62021-06-22 09:23:17,291 [application-name] [main] WARNo.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'redisConnectionFactory' defined in class path resource [org/springframework/boot/autoconfigure/data/redis/LettuceConnectionConfiguration.class]: Bean instantiation via factory method failed;
nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory]: Factory method 'redisConnectionFactory' threw exception;
nested exception is java.lang.NoClassDefFoundError: org/apache/commons/pool2/impl/GenericObjectPoolConfig
72021-06-22 09:23:17,343 [application-name] [main] ERROR o.s.b.SpringApplication - Application run failed
8org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'redisConnectionFactory' defined in class path resource [org/springframework/boot/autoconfigure/data/redis/LettuceConnectionConfiguration.class]: Bean instantiation via factory method failed;
nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory]: Factory method 'redisConnectionFactory' threw exception;
nested exception is java.lang.NoClassDefFoundError: org/apache/commons/pool2/impl/GenericObjectPoolConfig
9at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:657)
10at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:637)
11at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1341)
12at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1181)
13at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:556)
14at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516)
15at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324)
16at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
17at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322)
18at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
19at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:897)
20at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879)
21at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551)
22at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143)
23at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758)
24at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750)
25at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:405)
26at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
27at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237)
28at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
29at com.ichinae.imis.MgrApplication.main(MgrApplication.java:20)
30at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
31at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
32at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
33at java.lang.reflect.Method.invoke(Method.java:498)
34at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
35at org.springframework.boot.loader.Launcher.launch(Launcher.java:107)
36at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
37at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88)
38Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory]: Factory method 'redisConnectionFactory' threw exception;
nested exception is java.lang.NoClassDefFoundError: org/apache/commons/pool2/impl/GenericObjectPoolConfig
39at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
40at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:652)
41... 28 common frames omitted
42Caused by: java.lang.NoClassDefFoundError: org/apache/commons/pool2/impl/GenericObjectPoolConfig
43at org.springframework.data.redis.connection.lettuce.LettucePoolingClientConfiguration$LettucePoolingClientConfigurationBuilder.(LettucePoolingClientConfiguration.java:94)
44at org.springframework.data.redis.connection.lettuce.LettucePoolingClientConfiguration.builder(LettucePoolingClientConfiguration.java:51)
45at org.springframework.boot.autoconfigure.data.redis.LettuceConnectionConfiguration$PoolBuilderFactory.createBuilder(LettuceConnectionConfiguration.java:159)
46at org.springframework.boot.autoconfigure.data.redis.LettuceConnectionConfiguration.createBuilder(LettuceConnectionConfiguration.java:107)
47at org.springframework.boot.autoconfigure.data.redis.LettuceConnectionConfiguration.getLettuceClientConfiguration(LettuceConnectionConfiguration.java:92)
48at org.springframework.boot.autoconfigure.data.redis.LettuceConnectionConfiguration.redisConnectionFactory(LettuceConnectionConfiguration.java:74)
49at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
50at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
51at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
52at java.lang.reflect.Method.invoke(Method.java:498)
53at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
54... 29 common frames omitted
55Caused by: java.lang.ClassNotFoundException: org.apache.commons.pool2.impl.GenericObjectPoolConfig
56at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
57at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
58at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:151)
59at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
60... 40 common frames omitted
像往常一样,copy 异常信息,粘贴的google搜一下,然后介绍的都是价格以apache common pool2 的依赖,然后还有竟然说重建一个项目到。。。(兄弟你搞笑的吧)。来说下这个异常的原因,报这个错的去看下你的配置文件中是不是配置了 lettuce.pool 的配置信息,
如果有那就对了,解决的方法有两个:
- 因为启动时来加载器找不到common-pool2的相关类,那么就给它把相关类引入,添加依赖:
org.apache.commons commons-pool2
- 移除lettuce.pool的配置,如果你都用不到,或者都是复制过来的配置,就用默认的就可以,删除这个相关配置。
推荐阅读
- 关于|关于 java.lang.NoClassDefFoundError: com.umeng.analytics.d的问题
- 后端|ClassNotFoundException 和 NoClassDefFoundError 有什么区别()
- AdoptOpenJDK|AdoptOpenJDK 导致的 java.lang.NoClassDefFoundError 问题
- OracleJdk与openJdk差异引起的NoClassDefFoundError/ClassNotFoundException
- java.lang2.NoClassDefFoundError: Failed resolution of: Landroid/support/v7/widget/TintManager;
- hbase|HDFS上数据保存到Hbase运行报错(NoClassDefFoundError: org/apache/hadoop/hbase/HBaseConfiguration)
- kotlin使用let报java.lang.NoClassDefFoundError
- java.lang.NoClassDefFoundError:|java.lang.NoClassDefFoundError: Could not initialize class