Factory method 'redisConnectionFactory' threw exception; nested exception is java.lang.NoClassDefFou

springBoot 项目使用redis缓存,项目启动报错:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'authController': 
Unsatisfied dependency expressed through field 'authService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'authService': Unsatisfied dependency expressed through field 'redisTemplate'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: 
Error creating bean with name 'stringRedisTemplate' defined in class path resource [org/springframework/boot/autoconfigure/data/redis/RedisAutoConfiguration.class]: 
Unsatisfied dependency expressed through method 'stringRedisTemplate' parameter 0; nested exception is 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

报错原因: java.lang.NoClassDefFoundError: org/apache/commons/pool2/impl/GenericObjectPoolConfig
故加入依赖commons-pool2即可:

		<dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-pool2</artifactId>
        </dependency>

commons-pool2:对象池依赖,从名字可知其大概作用,其深层次东西暂未研究,只知道springBoot这里用redis需要加入该依赖;若有乱用的情况,还请指出;

发布了41 篇原创文章 · 获赞 22 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/qq1049545450/article/details/83025233