(Do not request a bean from a BeanFactory in a destroy method implementation!)

Time:2022-5-26

Exception: Singleton bean creation not allowed while singletons of this factory are in destruction (do not request a bean from a beanfactory in a destruction method implementation!)

If your project references spring cloud starter Zipkin jar and spring boot starter data redis jar at the same time, redis will not be connected and this exception will occur
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!)

reason

Spring cloud starter Zipkin and lettuce may be incompatible,
This causes the redis client lettuce to be unable to connect to redis, resulting in an error

resolvent

Remove the reference to lettuce in spring boot starter data redis and add jedis Maven dependency
The code is as follows:

<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>

Problem solving