Caused by: java.lang.NoClassDefFoundError: redis/clients/util/Pool解析

java哥 阅读:224 2021-03-31 18:14:44 评论:0
  
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jedisConnectionFactory' defined in class path resource [spring-redis.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.redis.connection.jedis.JedisConnectionFactory]: No default constructor found; nested exception is java.lang.NoClassDefFoundError: redis/clients/util/Pool 
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1270) 
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1164) 
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:538) 
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498) 
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) 
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) 
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) 
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) 
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:846) 
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:863) 
	at org.springframework.context.support.AbstractApplicationContext.__refresh(AbstractApplicationContext.java:546) 
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java) 
	at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:400) 
	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:291) 
	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:103) 
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939) 
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434) 
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) 
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559) 
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549) 
	at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 
	at java.lang.Thread.run(Thread.java:745) 
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.redis.connection.jedis.JedisConnectionFactory]: No default constructor found; nested exception is java.lang.NoClassDefFoundError: redis/clients/util/Pool 
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:83) 
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1262) 
	... 23 more 
Caused by: java.lang.NoClassDefFoundError: redis/clients/util/Pool 
	at java.lang.Class.getDeclaredConstructors0(Native Method) 
	at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671) 
	at java.lang.Class.getConstructor0(Class.java:3075) 
	at java.lang.Class.getDeclaredConstructor(Class.java:2178) 
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:78) 
	... 24 more 
Caused by: java.lang.ClassNotFoundException: redis.clients.util.Pool 
	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1702) 
	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1547) 
	... 29 more 
 

问题原因:pom.xml中引入的两个redis相关jar不兼容.

  
		<!--Spring整合redis包 --> 
		<dependency> 
			<groupId>org.springframework.data</groupId> 
			<artifactId>spring-data-redis</artifactId> 
			<version>2.1.3.RELEASE</version> 
		</dependency> 
		<dependency> 
			<groupId>redis.clients</groupId> 
			<artifactId>jedis</artifactId> 
			<version>3.0.0</version> 
		</dependency> 
        <!--redis 依赖common-pool2 --> 
		<dependency> 
			<groupId>org.apache.commons</groupId> 
			<artifactId>commons-pool2</artifactId> 
			<version>2.4.3</version> 
		</dependency>

解决办法:降低redis.clients的版本:

  
		<!--Spring整合redis包 --> 
		<dependency> 
			<groupId>org.springframework.data</groupId> 
			<artifactId>spring-data-redis</artifactId> 
			<version>2.1.3.RELEASE</version> 
		</dependency> 
		<!-- https://mvnrepository.com/artifact/redis.clients/jedis --> 
		<!-- https://mvnrepository.com/artifact/redis.clients/jedis --> 
		<dependency> 
			<groupId>redis.clients</groupId> 
			<artifactId>jedis</artifactId> 
			<version>2.9.1</version> 
		</dependency> 
        <!--redis 依赖common-pool2 --> 
		<dependency> 
			<groupId>org.apache.commons</groupId> 
			<artifactId>commons-pool2</artifactId> 
			<version>2.4.3</version> 
		</dependency>

 

声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

发表评论
搜索
排行榜
KIKK导航

KIKK导航

关注我们