spring @Resource为找到
时间: 2023-08-16 10:17:20 浏览: 107
回答: 当使用Spring的@Resource注解时,如果没有找到匹配的bean,会抛出异常。这可能是因为没有在Spring上下文中找到与@Resource注解中指定的name或type属性匹配的bean。\[1\] @Resource注解是JSR-250提供的Java标准注解,大多数框架都支持它。与之相比,@Autowired注解是Spring框架特有的注解,如果切换到其他框架,@Autowired注解可能会失效。\[2\] 在使用@Resource注解时,可以通过指定name属性或type属性来精确匹配要注入的bean。如果没有指定name属性,则会根据type属性来查找唯一匹配的bean进行注入。如果找不到匹配的bean或找到多个匹配的bean,则会抛出异常。\[3\]
#### 引用[.reference_title]
- *1* [Spring @Resource注解](https://blog.csdn.net/qq_36761831/article/details/90294875)[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^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [Spring中@Autowired和@Resource的区别](https://blog.csdn.net/Weixiaohuai/article/details/120853683)[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^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item]
- *3* [一文弄懂Spring源码之@Resource注解](https://blog.csdn.net/q1472750149/article/details/122213803)[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^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文