解决@Autowire在springboot启动是报No qualifying bean的问题

针对RedisTemplate封装了一个RedisUtils类,在调用时使用@Autowire注入此类,出现报错,内容如下

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.popmart.testcontainer.testcase.OmsTest':
Unsatisfied dependency expressed through field 'redisUtils'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.popmart.config.redis.RedisUtils' available:
expected at least 1 bean which qualifies as autowire candidate.
Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

解决思路:

1.根据保存分析原因:从报错信息无法扫描到redisUtils这个bean,如果@Autowire使用注释进行配置,则可能会缺少cn.itcast.crm.service.BaseDictService实现的注释(@Service或@Component等)。

2.在RedisUtils类尝试着增加了@Service或@Component后问题解决,增加了@server注解后springboot启动可扫描到此bean。

 

posted @ 2020-12-31 14:07  yull0408  阅读(1449)  评论(0编辑  收藏  举报