spring @Autowired注入map

注入map,平常一般不会这么做,今天看一段老代码时发现有这么个用法。补习一下。

 @Autowired 标注作用于 Map 类型时,如果 Map 的 key 为 String 类型,则 Spring 会将容器中所有类型符合 Map 的 value 对应的类型的 Bean 增加进来,用 Bean 的 id 或 name 作为 Map 的 key。

 

原文地址:https://www.cnblogs.com/zhjh256/p/11179678.html