异常:Singleton bean creation not allowed while singletons of this factory are in destruction (Do not request a bean from a BeanFactory in a destroy method implementation!)
假如你的项目同时引用spring-cloud-starter-zipkin这个jar和spring-boot-starter-data-redis这个jar就会连不上redis并且会出这个异常
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘scopedTarget.defaultTraceSampler’ defined in class path resource [org/springframework/cloud/sleuth/sampler/SamplerAutoConfiguration$RefreshScopedSamplerConfiguration.class]: Unsatisfied dependency expressed through method ‘defaultTraceSampler’ parameter 0; nested exception is org.springframework.beans.factory.BeanCreationNotAllowedException: Error creating bean with name ‘spring.sleuth.sampler-org.springframework.cloud.sleuth.sampler.SamplerProperties’: Singleton bean creation not allowed while singletons of this factory are in destruction (Do not request a bean from a BeanFactory in a destroy method implementation!)
原因
spring-cloud-starter-zipkin 和lettuce可能不兼容,
导致Redis 客户端lettuce无法连接上Redis导致该报错
解决方法
移除spring-boot-starter-data-redis中对lettuce的引用,加入jedis的Maven依赖
代码如下:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<exclusions>
<exclusion>
<groupId>io.lettuce</groupId>
<artifactId>lettuce-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
</dependency>
问题解决