1. 程式人生 > >Factory method 'redisConnectionFactory' threw exception; nested exception is java.lang.NoClassDefFou

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需要加入該依賴;若有亂用的情況,還請指出;