spring boot 整合redis 报错(在redis中存储数据报错)
2023-06-30 16:03:00.067 WARN 34296 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'rdiMesController': Unsatisfied dependency expressed through field 'rdiMesService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'rdiMesServiceImpl': Unsatisfied dependency expressed through field 'soRedisTemplate'; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'org.springframework.data.redis.core.RedisTemplate<?, ?>' available: expected single matching bean but found 2: redisTemplate,stringRedisTemplate
2023-06-30 16:03:00.067 INFO 34296 --- [ main] c.b.d.d.DynamicRoutingDataSource : dynamic-datasource start closing ....
2023-06-30 16:03:00.067 INFO 34296 --- [ main] c.b.d.d.DynamicRoutingDataSource : dynamic-datasource all closed success,bye
2023-06-30 16:03:00.069 INFO 34296 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2023-06-30 16:03:00.087 INFO 34296 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2023-06-30 16:03:00.103 ERROR 34296 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
Description:
Field soRedisTemplate in com.ruoyi.rdimes.service.impl.RdiMesServiceImpl required a single bean, but 2 were found:
- redisTemplate: defined by method 'redisTemplate' in class path resource [com/ruoyi/common/redis/configure/RedisConfig.class]
- stringRedisTemplate: defined by method 'stringRedisTemplate' in class path resource [org/springframework/boot/autoconfigure/data/redis/RedisAutoConfiguration.class]
Action:
Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed
2023-06-30 16:03:00.104 WARN 34296 --- [ Thread-1] c.a.n.common.http.HttpClientBeanHolder : [HttpClientBeanHolder] Start destroying common HttpClient
2023-06-30 16:03:00.105 WARN 34296 --- [ Thread-5] c.a.nacos.common.notify.NotifyCenter : [NotifyCenter] Start destroying Publisher
2023-06-30 16:03:00.105 WARN 34296 --- [ Thread-5] c.a.nacos.common.notify.NotifyCenter : [NotifyCenter] Destruction of the end
Process finished with exit code 1
***************************
APPLICATION FAILED TO START
***************************
解决办法增加注解Qualifier
原注解代码
@Autowired
private RedisTemplate soRedisTemplate;//支持redis五大类型中的所有类型
改后注解代码
@Autowired
@Qualifier("redisTemplate")
private RedisTemplate soRedisTemplate;//支持redis五大类型中的所有类型
成功存储数据并且取到