解決@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