一、错误
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mvcConfig': Injection of resource dependencies failed; 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 [org/springframework/boot/autoconfigure/data/redis/LettuceConnectionConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [io.lettuce.core.resource.DefaultClientResources]: Factory method 'lettuceClientResources' threw exception; nested exception is java.lang.NoClassDefFoundError: reactor/core/publisher/Sinks
二、原因
这个错误的原因是项目中缺少了 reactor-core
的依赖项。根据错误信息,这个问题可能与 Redis 和 Lettuce 的配置有关。
三、解决
可以通过在项目的构建文件中添加以下 Maven 依赖项来解决这个问题:
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-core</artifactId>
<version>3.4.11</version>
</dependency>
确保版本号与你的项目中其他依赖项的版本一致。
添加了 reactor-core
依赖项后,重新构建并运行项目,应该就可以解决这个错误了。