No qualifying bean of type 'com.xxx' available: expected at least 1 bean which qualifies as autowire
时间: 2023-10-31 20:55:58 浏览: 261
报错信息"No qualifying bean of type 'com.xxx' available: expected at least 1 bean which qualifies as autowire candidate"表示没有符合自动装配条件的类型为'com.xxx'的bean可用。
根据报错信息中提到的入口方法"org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1356)",我们可以看到问题出现在AServiceImpl的构造函数中,其中的最后一个入参是String类型。
解决该问题的方式有三种:
1. 使用@Autowired注解对属性或者方法进行Bean的注入。然而,从Spring 4.0开始,不再推荐使用属性注入模式,因为它会隐藏一些可能导致代码出错的隐患。
2. 使用@RequiredArgsConstructor(onConstructor =@_(@Autowired))注解,这样默认会通过@Autowired注入Bean。
3. 使用@RequiredArgsConstructor(onConstructor_={@Lazy})注解,对Bean进行懒加载处理。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [No qualifying bean of type ‘java.lang.Long‘ available: expected at least 1 bean which qualifies as...](https://blog.csdn.net/zzztimes/article/details/124981326)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatgptT3_1"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [No qualifying bean of type ‘java.lang.String‘ available: expected at least 1 bean which qualifies](https://blog.csdn.net/Saintmm/article/details/125941552)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatgptT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文