-
报错信息:
sh Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userController': Unsatisfied dependency expressed through field 'stringRedisTemplate'; 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.UnsatisfiedDependencyException: Error creating bean with name 'redisConnectionFactory' defined in class path resource [org/springframework/boot/autoconfigure/data/redis/LettuceConnectionConfiguration.class]: Unsatisfied dependency expressed through method 'redisConnectionFactory' parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'lettuceClientResources' defined in class path resource
-
这里是Controller类报错,不过异常都是一层一层往外抛的,所以一直往下看,会发现是 ‘lettuceClientResources’ 出错了, 如果你的redis连接配置确保正确的话,有可能是你同时引入了netty的依赖,因为 spring-boot-starter-data-redis 中包含 lettuce-core依赖,而 lettuce-core 中又包含一些netty的依赖, 所以,如果你引入的netty依赖和lettuce-core中的不一样,就会出错。
-
解决: 查看lettuce-core中的netty版本,将自己的netty版本改成一样的。
具体做法:点击spring-boot-starter-data-redis依赖查找lettuce-core,再点进lettuce-core找netty,就可以看到版本号了
-
-
如果最后是 ‘redisConnectionFactory’ 报错, 那可能是连接池依赖没有引入, 需要引入该依赖:commons-pool2 ,且版本要对应,不然也会报错(不写版本号,用springboot管理的version就好)。
<!--ommon-pool--> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-pool2</artifactId> </dependency>
a