解决@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。

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM