@autowired map使用
时间: 2023-12-31 14:04:46 浏览: 183
@Autowire标注作用于Map类型时,Spring会将容器中所有类型符合Map的value对应的Bean增加进来,并以Bean的id或name作为Map的key。具体来说,当使用@Autowired注解注入一个Map类型的属性时,Spring会自动将所有符合Map value类型的Bean注入到这个Map中,以Bean的id或name作为Map的key。例如,在上述的示例中,Demo类中的setA方法和setB方法都使用@Autowired注解注入了Map类型的参数,Spring会将所有类型为A的Bean注入到aMap中,将所有类型为B的Bean注入到bMap中。这样,我们就可以通过aMap和bMap来获取对应的Bean实例了。
#### 引用[.reference_title]
- *1* [使用@Autowired对set方法参数是map的注入](https://blog.csdn.net/qq_36997245/article/details/105061279)[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^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [@Autowired自动注入map](https://blog.csdn.net/AttleeTao/article/details/126034525)[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^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
- *3* [SpringBoot中 使用@Autowired 将bean注入到List或Map等集合中](https://blog.csdn.net/inrgihc/article/details/104742206)[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^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文